Skip to content

Commit f26d6a0

Browse files
authored
ObjC Fixes / Example updates / Signature updates (#215)
* ObjC Fixes / Example updates * ObjC Fixes, Example Updates, Signature adaptations * Disable linux compile for some test infra * Use iPhone 14 in iOS test * Again ...
1 parent 26f23a2 commit f26d6a0

File tree

10 files changed

+83
-16
lines changed

10 files changed

+83
-16
lines changed

.github/workflows/swift.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
- uses: webfactory/[email protected]
5858
with:
5959
ssh-private-key: ${{ secrets.SOVRAN_SSH_KEY }}
60-
- run: xcodebuild -scheme Segment-Package test -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 11'
60+
- run: xcodebuild -scheme Segment-Package test -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 13'
6161

6262

6363
build_and_test_tvos:

Examples/apps/ObjCExample/ObjCExample.xcodeproj/project.pbxproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/* Begin PBXBuildFile section */
1010
460FF309299AAEEC00635FF9 /* Segment in Frameworks */ = {isa = PBXBuildFile; productRef = 460FF308299AAEEC00635FF9 /* Segment */; };
1111
46262AB229CB731B005C68FF /* SegmentMixpanel in Frameworks */ = {isa = PBXBuildFile; productRef = 46262AB129CB731B005C68FF /* SegmentMixpanel */; };
12+
463F61EA29E9C33400BBB4ED /* TestDestination.swift in Sources */ = {isa = PBXBuildFile; fileRef = 463F61E929E9C33400BBB4ED /* TestDestination.swift */; };
1213
464247BC26C6D7A700CAD301 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 464247BB26C6D7A700CAD301 /* AppDelegate.m */; };
1314
464247BF26C6D7A700CAD301 /* SceneDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 464247BE26C6D7A700CAD301 /* SceneDelegate.m */; };
1415
464247C226C6D7A700CAD301 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 464247C126C6D7A700CAD301 /* ViewController.m */; };
@@ -19,6 +20,8 @@
1920
/* End PBXBuildFile section */
2021

2122
/* Begin PBXFileReference section */
23+
463F61E829E9C33400BBB4ED /* ObjCExample-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ObjCExample-Bridging-Header.h"; sourceTree = "<group>"; };
24+
463F61E929E9C33400BBB4ED /* TestDestination.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestDestination.swift; sourceTree = "<group>"; };
2225
464247B726C6D7A700CAD301 /* ObjCExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ObjCExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
2326
464247BA26C6D7A700CAD301 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
2427
464247BB26C6D7A700CAD301 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
@@ -66,6 +69,7 @@
6669
464247B926C6D7A700CAD301 /* ObjCExample */ = {
6770
isa = PBXGroup;
6871
children = (
72+
463F61E929E9C33400BBB4ED /* TestDestination.swift */,
6973
464247BA26C6D7A700CAD301 /* AppDelegate.h */,
7074
464247BB26C6D7A700CAD301 /* AppDelegate.m */,
7175
464247BD26C6D7A700CAD301 /* SceneDelegate.h */,
@@ -77,6 +81,7 @@
7781
464247C826C6D7A800CAD301 /* LaunchScreen.storyboard */,
7882
464247CB26C6D7A800CAD301 /* Info.plist */,
7983
464247CC26C6D7A800CAD301 /* main.m */,
84+
463F61E829E9C33400BBB4ED /* ObjCExample-Bridging-Header.h */,
8085
);
8186
path = ObjCExample;
8287
sourceTree = "<group>";
@@ -122,6 +127,7 @@
122127
TargetAttributes = {
123128
464247B626C6D7A700CAD301 = {
124129
CreatedOnToolsVersion = 12.5.1;
130+
LastSwiftMigration = 1430;
125131
};
126132
};
127133
};
@@ -164,6 +170,7 @@
164170
isa = PBXSourcesBuildPhase;
165171
buildActionMask = 2147483647;
166172
files = (
173+
463F61EA29E9C33400BBB4ED /* TestDestination.swift in Sources */,
167174
464247C226C6D7A700CAD301 /* ViewController.m in Sources */,
168175
464247BC26C6D7A700CAD301 /* AppDelegate.m in Sources */,
169176
464247CD26C6D7A800CAD301 /* main.m in Sources */,
@@ -310,6 +317,7 @@
310317
buildSettings = {
311318
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
312319
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
320+
CLANG_ENABLE_MODULES = YES;
313321
CODE_SIGN_STYLE = Automatic;
314322
INFOPLIST_FILE = ObjCExample/Info.plist;
315323
LD_RUNPATH_SEARCH_PATHS = (
@@ -318,6 +326,9 @@
318326
);
319327
PRODUCT_BUNDLE_IDENTIFIER = com.segment.ObjCExample;
320328
PRODUCT_NAME = "$(TARGET_NAME)";
329+
SWIFT_OBJC_BRIDGING_HEADER = "ObjCExample/ObjCExample-Bridging-Header.h";
330+
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
331+
SWIFT_VERSION = 5.0;
321332
TARGETED_DEVICE_FAMILY = "1,2";
322333
};
323334
name = Debug;
@@ -327,6 +338,7 @@
327338
buildSettings = {
328339
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
329340
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
341+
CLANG_ENABLE_MODULES = YES;
330342
CODE_SIGN_STYLE = Automatic;
331343
INFOPLIST_FILE = ObjCExample/Info.plist;
332344
LD_RUNPATH_SEARCH_PATHS = (
@@ -335,6 +347,8 @@
335347
);
336348
PRODUCT_BUNDLE_IDENTIFIER = com.segment.ObjCExample;
337349
PRODUCT_NAME = "$(TARGET_NAME)";
350+
SWIFT_OBJC_BRIDGING_HEADER = "ObjCExample/ObjCExample-Bridging-Header.h";
351+
SWIFT_VERSION = 5.0;
338352
TARGETED_DEVICE_FAMILY = "1,2";
339353
};
340354
name = Release;

Examples/apps/ObjCExample/ObjCExample/AppDelegate.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77

88
#import "AppDelegate.h"
9+
#import "ObjCExample-Swift.h"
910

1011
@import Segment;
1112
@import SegmentMixpanel;
@@ -29,6 +30,9 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
2930

3031
[self.analytics flush];
3132

33+
SEGTestDestination *testDestination = [[SEGTestDestination alloc] init];
34+
[self.analytics addPlugin:testDestination];
35+
3236
[self.analytics addSourceMiddleware:^NSDictionary<NSString *,id> * _Nullable(NSDictionary<NSString *,id> * _Nullable event) {
3337
// drop all events named booya
3438
NSString *eventType = event[@"type"];

Examples/apps/ObjCExample/ObjCExample/Info.plist

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@
1616
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
1717
<key>CFBundleShortVersionString</key>
1818
<string>1.0</string>
19+
<key>CFBundleURLTypes</key>
20+
<array>
21+
<dict>
22+
<key>CFBundleTypeRole</key>
23+
<string>Editor</string>
24+
<key>CFBundleURLSchemes</key>
25+
<array/>
26+
</dict>
27+
</array>
1928
<key>CFBundleVersion</key>
2029
<string>1</string>
2130
<key>LSRequiresIPhoneOS</key>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//
2+
// Use this file to import your target's public headers that you would like to expose to Swift.
3+
//
4+
5+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// TestDestination.swift
3+
// ObjCExample
4+
//
5+
// Created by Brandon Sneed on 4/14/23.
6+
//
7+
8+
import Foundation
9+
import Segment
10+
11+
@objc(SEGTestDestination)
12+
public class ObjCTestDestination: NSObject, ObjCPlugin, ObjCPluginShim {
13+
public func instance() -> EventPlugin { return TestDestination() }
14+
}
15+
16+
public class TestDestination: DestinationPlugin {
17+
public let key = "Booya"
18+
public let timeline = Timeline()
19+
public let type = PluginType.destination
20+
public var analytics: Analytics? = nil
21+
22+
public func execute<T: RawEvent>(event: T?) -> T? {
23+
print("some event came to visit us for xmas din din.")
24+
return event
25+
}
26+
}

Sources/Segment/Events.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ extension Analytics {
142142
/// generate the UUID and Apple's policies on IDs, see
143143
/// https://segment.io/libraries/ios#ids
144144
/// - properties: A dictionary of traits you know about the user. Things like: email, name, plan, etc.
145-
public func track(name: String, properties: [String: Codable]? = nil) {
145+
public func track(name: String, properties: [String: Any]? = nil) {
146146
var props: JSON? = nil
147147
if let properties = properties {
148148
do {
@@ -165,7 +165,7 @@ extension Analytics {
165165
/// https://segment.io/libraries/ios#ids
166166
/// - traits: A dictionary of traits you know about the user. Things like: email, name, plan, etc.
167167
/// In the case when user logs out, make sure to call ``reset()`` to clear user's identity info.
168-
public func identify(userId: String, traits: [String: Codable]? = nil) {
168+
public func identify(userId: String, traits: [String: Any]? = nil) {
169169
do {
170170
if let traits = traits {
171171
let traits = try JSON(traits as Any)
@@ -187,7 +187,7 @@ extension Analytics {
187187
/// - screenTitle: The title of the screen being tracked.
188188
/// - category: A category to the type of screen if it applies.
189189
/// - properties: Any extra metadata associated with the screen. e.g. method of access, size, etc.
190-
public func screen(title: String, category: String? = nil, properties: [String: Codable]? = nil) {
190+
public func screen(title: String, category: String? = nil, properties: [String: Any]? = nil) {
191191
var event = ScreenEvent(title: title, category: category, properties: nil)
192192
if let properties = properties {
193193
do {
@@ -204,7 +204,7 @@ extension Analytics {
204204
/// - Parameters:
205205
/// - groupId: A unique identifier for the group identification in your system.
206206
/// - traits: Traits of the group you may be interested in such as email, phone or name.
207-
public func group(groupId: String, traits: [String: Codable]?) {
207+
public func group(groupId: String, traits: [String: Any]?) {
208208
var event = GroupEvent(groupId: groupId)
209209
if let traits = traits {
210210
do {

Sources/Segment/ObjC/ObjCDestinationSupport.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99

1010
import Foundation
1111

12-
@objc(SEGDestination)
13-
public protocol ObjCDestination {}
12+
@objc(SEGPlugin)
13+
public protocol ObjCPlugin {}
1414

15-
public protocol ObjCDestinationShim {
16-
func instance() -> DestinationPlugin
15+
public protocol ObjCPluginShim {
16+
func instance() -> EventPlugin
1717
}
1818

1919
// NOTE: Destination plugins need something similar to the following to work
@@ -22,8 +22,8 @@ public protocol ObjCDestinationShim {
2222
/*
2323

2424
@objc(SEGMixpanelDestination)
25-
public class ObjCSegmentMixpanel: NSObject, ObjCDestination, ObjCDestinationShim {
26-
public func instance() -> DestinationPlugin { return MixpanelDestination() }
25+
public class ObjCSegmentMixpanel: NSObject, ObjCPlugin, ObjCPluginShim {
26+
public func instance() -> EventPlugin { return MixpanelDestination() }
2727
}
2828

2929
*/

Sources/Segment/ObjC/ObjCPluginSupport.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,11 @@ extension ObjCAnalytics {
113113
_ = dest.add(plugin: ObjCShimPlugin(middleware: middleware))
114114
}
115115

116-
@objc(addDestination:)
117-
public func addDestination(_ destination: ObjCDestination) {
118-
guard let bouncer = destination as? ObjCDestinationShim else { return }
119-
let dest = bouncer.instance()
120-
analytics.add(plugin: dest)
116+
@objc(addPlugin:)
117+
public func add(plugin: ObjCPlugin) {
118+
guard let bouncer = plugin as? ObjCPluginShim else { return }
119+
let p = bouncer.instance()
120+
analytics.add(plugin: p)
121121
}
122122
}
123123

Tests/Segment-Tests/Support/TestUtilities.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ class ZiggyPlugin: EventPlugin {
6161
}
6262
}
6363

64+
#if !os(Linux)
65+
66+
@objc(SEGMyDestination)
67+
public class ObjCMyDestination: NSObject, ObjCPlugin, ObjCPluginShim {
68+
public func instance() -> EventPlugin { return MyDestination() }
69+
}
70+
71+
#endif
72+
6473
class MyDestination: DestinationPlugin {
6574
var timeline: Timeline
6675
let type: PluginType

0 commit comments

Comments
 (0)