Skip to content

Commit 6eb8192

Browse files
authored
Objective-C API improvements (#219)
* Alternative ObjC * Test updates * Doc/Convenience updates * Removed writekey * Fix commented file names. * Fixed project * Project updates
1 parent 035c455 commit 6eb8192

22 files changed

+688
-212
lines changed

.github/workflows/swift.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616

1717
build_and_test_spm_mac:
1818
needs: cancel_previous
19-
runs-on: macos-11
19+
runs-on: macos-latest
2020
steps:
2121
- uses: maxim-lobanov/setup-xcode@v1
2222
with:
@@ -48,9 +48,9 @@ jobs:
4848

4949
build_and_test_ios:
5050
needs: cancel_previous
51-
runs-on: macos-11
51+
runs-on: macos-latest
5252
steps:
53-
- uses: maxim-lobanov/setup-xcode@v1.5.1
53+
- uses: maxim-lobanov/setup-xcode@v1
5454
with:
5555
xcode-version: latest-stable
5656
- uses: actions/checkout@v2
@@ -62,7 +62,7 @@ jobs:
6262

6363
build_and_test_tvos:
6464
needs: cancel_previous
65-
runs-on: macos-11
65+
runs-on: macos-latest
6666
steps:
6767
- uses: maxim-lobanov/setup-xcode@v1
6868
with:
@@ -75,7 +75,7 @@ jobs:
7575

7676
build_and_test_watchos:
7777
needs: cancel_previous
78-
runs-on: macos-11
78+
runs-on: macos-latest
7979
steps:
8080
- uses: maxim-lobanov/setup-xcode@v1
8181
with:
@@ -84,13 +84,13 @@ jobs:
8484
- uses: webfactory/[email protected]
8585
with:
8686
ssh-private-key: ${{ secrets.SOVRAN_SSH_KEY }}
87-
- run: xcodebuild -scheme Segment-Package test -sdk watchsimulator -destination 'platform=watchOS Simulator,name=Apple Watch Series 5 - 40mm'
87+
- run: xcodebuild -scheme Segment-Package test -sdk watchsimulator -destination 'platform=watchOS Simulator,name=Apple Watch Series 8 (45mm)'
8888

8989
build_and_test_examples:
9090
needs: cancel_previous
91-
runs-on: macos-12
91+
runs-on: macos-latest
9292
steps:
93-
- uses: maxim-lobanov/setup-xcode@v1.5.1
93+
- uses: maxim-lobanov/setup-xcode@v1
9494
with:
9595
xcode-version: latest-stable
9696
- uses: actions/checkout@v2

Examples/apps/ObjCExample/ObjCExample/AppDelegate.m

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ @implementation AppDelegate
2020

2121
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
2222
// Override point for customization after application launch.
23-
SEGConfiguration *config = [[SEGConfiguration alloc] initWithWriteKey:@"<writekey>"];
23+
SEGConfiguration *config = [[SEGConfiguration alloc] initWithWriteKey:@"<WRITE KEY>"];
2424
config.trackApplicationLifecycleEvents = YES;
25+
config.flushAt = 1;
2526

2627
_analytics = [[SEGAnalytics alloc] initWithConfiguration: config];
2728

@@ -33,23 +34,44 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
3334
SEGTestDestination *testDestination = [[SEGTestDestination alloc] init];
3435
[self.analytics addPlugin:testDestination];
3536

36-
[self.analytics addSourceMiddleware:^NSDictionary<NSString *,id> * _Nullable(NSDictionary<NSString *,id> * _Nullable event) {
37-
// drop all events named booya
38-
NSString *eventType = event[@"type"];
39-
if ([eventType isEqualToString:@"track"]) {
40-
NSString *eventName = event[@"event"];
41-
if ([eventName isEqualToString:@"booya"]) {
42-
return nil;
43-
}
37+
SEGBlockPlugin *customizeAllTrackCalls = [[SEGBlockPlugin alloc] initWithBlock:^id<SEGRawEvent> _Nullable(id<SEGRawEvent> _Nullable event) {
38+
if ([event isKindOfClass: [SEGTrackEvent class]]) {
39+
SEGTrackEvent *track = (SEGTrackEvent *)event;
40+
// change the name
41+
NSString *newName = [NSString stringWithFormat: @"[New] %@", track.event];
42+
track.event = newName;
43+
// add a property
44+
NSMutableDictionary *newProps = (track.properties != nil) ? [track.properties mutableCopy] : [@{} mutableCopy];
45+
newProps[@"customAttribute"] = @"Hello";
46+
track.properties = newProps;
47+
48+
return track;
4449
}
4550
return event;
4651
}];
4752

48-
//[self.analytics addDestination:[[SEGMixpanelDestination alloc] init]];
53+
[self.analytics addPlugin:customizeAllTrackCalls];
4954

55+
SEGBlockPlugin *booyaAllTrackCalls = [[SEGBlockPlugin alloc] initWithBlock:^id<SEGRawEvent> _Nullable(id<SEGRawEvent> _Nullable event) {
56+
if ([event isKindOfClass: [SEGTrackEvent class]]) {
57+
SEGTrackEvent *track = (SEGTrackEvent *)event;
58+
// change the name
59+
NSString *newName = [NSString stringWithFormat: @"[Booya] %@", track.event];
60+
track.event = newName;
61+
// add a property
62+
NSMutableDictionary *newProps = (track.properties != nil) ? [track.properties mutableCopy] : [@{} mutableCopy];
63+
newProps[@"customAttribute"] = @"Booya!";
64+
track.properties = newProps;
65+
66+
return track;
67+
}
68+
return event;
69+
}];
5070

71+
[self.analytics addPlugin:booyaAllTrackCalls destinationKey:@"Segment.io"];
72+
5173
dispatch_async(dispatch_get_main_queue(), ^{
52-
[self.analytics track:@"booya"];
74+
[self.analytics track:@"schneeble schnobble"];
5375
});
5476

5577
return YES;

Examples/apps/ObjCExample/ObjCExample/TestDestination.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,18 @@ public class TestDestination: DestinationPlugin {
1919
public let type = PluginType.destination
2020
public var analytics: Analytics? = nil
2121

22-
public func execute<T: RawEvent>(event: T?) -> T? {
23-
print("some event came to visit us for xmas din din.")
22+
public func configure(analytics: Analytics) {
23+
analytics.manuallyEnableDestination(plugin: self)
24+
self.analytics = analytics
25+
}
26+
27+
public func update(settings: Settings, type: UpdateType) {
28+
// analytics?.manuallyEnableDestination(plugin: self)
29+
}
30+
31+
public func track(event: TrackEvent) -> TrackEvent? {
32+
print("Event Received: \n")
33+
print(event.prettyPrint())
2434
return event
2535
}
2636
}

Segment.xcodeproj/project.pbxproj

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@
3636
465879BB2686560C00180335 /* watchOSLifecycleMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 465879B92686560C00180335 /* watchOSLifecycleMonitor.swift */; };
3737
4663C729267A799100ADDD1A /* QueueTimer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4663C728267A799100ADDD1A /* QueueTimer.swift */; };
3838
466EC2CE28FB7D5D001B384E /* OutputFileStream.swift in Sources */ = {isa = PBXBuildFile; fileRef = 466EC2CD28FB7D5D001B384E /* OutputFileStream.swift */; };
39+
4689231329F7391500AB26E5 /* ObjCPlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4689231129F7391500AB26E5 /* ObjCPlugin.swift */; };
40+
4689231429F7391500AB26E5 /* ObjCEvents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4689231229F7391500AB26E5 /* ObjCEvents.swift */; };
3941
4697A238290341EF00FAE14F /* Errors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4697A237290341EF00FAE14F /* Errors.swift */; };
4042
46A018C225E5857D00F9CCD8 /* Context.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46A018C125E5857D00F9CCD8 /* Context.swift */; };
4143
46A018D425E6C9C200F9CCD8 /* LinuxUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46A018D325E6C9C200F9CCD8 /* LinuxUtils.swift */; };
4244
46A018DA25E97FDF00F9CCD8 /* AppleUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46A018D925E97FDF00F9CCD8 /* AppleUtils.swift */; };
4345
46A018EE25E9A74F00F9CCD8 /* VendorSystem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46A018ED25E9A74F00F9CCD8 /* VendorSystem.swift */; };
44-
46A9439F29CE162A00D65DC3 /* ObjCDestinationSupport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46A9439D29CE162A00D65DC3 /* ObjCDestinationSupport.swift */; };
45-
46A943A029CE162A00D65DC3 /* ObjCPluginSupport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46A9439E29CE162A00D65DC3 /* ObjCPluginSupport.swift */; };
4646
46B1AC6927346D3D00846DE8 /* StressTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46B1AC6827346D3D00846DE8 /* StressTests.swift */; };
4747
46E382E72654429A00BA2502 /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46E382E62654429A00BA2502 /* Utils.swift */; };
4848
46F7485D26C718710042798E /* ObjCAnalytics.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46F7485B26C718710042798E /* ObjCAnalytics.swift */; };
@@ -125,13 +125,13 @@
125125
465879B92686560C00180335 /* watchOSLifecycleMonitor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = watchOSLifecycleMonitor.swift; sourceTree = "<group>"; };
126126
4663C728267A799100ADDD1A /* QueueTimer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QueueTimer.swift; sourceTree = "<group>"; };
127127
466EC2CD28FB7D5D001B384E /* OutputFileStream.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OutputFileStream.swift; sourceTree = "<group>"; };
128+
4689231129F7391500AB26E5 /* ObjCPlugin.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObjCPlugin.swift; sourceTree = "<group>"; };
129+
4689231229F7391500AB26E5 /* ObjCEvents.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObjCEvents.swift; sourceTree = "<group>"; };
128130
4697A237290341EF00FAE14F /* Errors.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Errors.swift; sourceTree = "<group>"; };
129131
46A018C125E5857D00F9CCD8 /* Context.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Context.swift; sourceTree = "<group>"; };
130132
46A018D325E6C9C200F9CCD8 /* LinuxUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinuxUtils.swift; sourceTree = "<group>"; };
131133
46A018D925E97FDF00F9CCD8 /* AppleUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleUtils.swift; sourceTree = "<group>"; };
132134
46A018ED25E9A74F00F9CCD8 /* VendorSystem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VendorSystem.swift; sourceTree = "<group>"; };
133-
46A9439D29CE162A00D65DC3 /* ObjCDestinationSupport.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObjCDestinationSupport.swift; sourceTree = "<group>"; };
134-
46A9439E29CE162A00D65DC3 /* ObjCPluginSupport.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObjCPluginSupport.swift; sourceTree = "<group>"; };
135135
46B1AC6827346D3D00846DE8 /* StressTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StressTests.swift; sourceTree = "<group>"; };
136136
46D98E3D26D6FEF300E7A86A /* FlurryDestination.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlurryDestination.swift; sourceTree = "<group>"; };
137137
46D98E3E26D6FEF300E7A86A /* AdjustDestination.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdjustDestination.swift; sourceTree = "<group>"; };
@@ -223,9 +223,9 @@
223223
isa = PBXGroup;
224224
children = (
225225
46F7485B26C718710042798E /* ObjCAnalytics.swift */,
226+
4689231229F7391500AB26E5 /* ObjCEvents.swift */,
227+
4689231129F7391500AB26E5 /* ObjCPlugin.swift */,
226228
46F7485C26C718710042798E /* ObjCConfiguration.swift */,
227-
46A9439D29CE162A00D65DC3 /* ObjCDestinationSupport.swift */,
228-
46A9439E29CE162A00D65DC3 /* ObjCPluginSupport.swift */,
229229
);
230230
path = ObjC;
231231
sourceTree = "<group>";
@@ -493,7 +493,7 @@
493493
attributes = {
494494
LastSwiftMigration = 9999;
495495
LastSwiftUpdateCheck = 1220;
496-
LastUpgradeCheck = 1340;
496+
LastUpgradeCheck = 1430;
497497
};
498498
buildConfigurationList = OBJ_2 /* Build configuration list for PBXProject "Segment" */;
499499
compatibilityVersion = "Xcode 3.2";
@@ -531,7 +531,6 @@
531531
46022764261E64A800A9E913 /* iOSLifecycleEvents.swift in Sources */,
532532
96A9624E2810C6B80011DE54 /* macOSLifecycleEvents.swift in Sources */,
533533
460FF30B29BA525900635FF9 /* Logging.swift in Sources */,
534-
46A9439F29CE162A00D65DC3 /* ObjCDestinationSupport.swift in Sources */,
535534
4621080C2605332D00EBC4A8 /* KeyPath.swift in Sources */,
536535
A31A16262576B6F200C9CDDF /* Timeline.swift in Sources */,
537536
96C33AB1258961F500F3D538 /* Settings.swift in Sources */,
@@ -543,15 +542,16 @@
543542
OBJ_23 /* Analytics.swift in Sources */,
544543
A31A16342576B7AF00C9CDDF /* Types.swift in Sources */,
545544
46A018DA25E97FDF00F9CCD8 /* AppleUtils.swift in Sources */,
545+
4689231429F7391500AB26E5 /* ObjCEvents.swift in Sources */,
546546
A31A16E12579779600C9CDDF /* Version.swift in Sources */,
547547
46210836260BBEE400EBC4A8 /* DeviceToken.swift in Sources */,
548548
9692724E25A4E5B7009B5298 /* Startup.swift in Sources */,
549549
4663C729267A799100ADDD1A /* QueueTimer.swift in Sources */,
550+
4689231329F7391500AB26E5 /* ObjCPlugin.swift in Sources */,
550551
46FE4C9C25A3F41C003A7362 /* LinuxLifecycleMonitor.swift in Sources */,
551552
460227422612987300A9E913 /* watchOSLifecycleEvents.swift in Sources */,
552553
46F7485E26C718710042798E /* ObjCConfiguration.swift in Sources */,
553554
759D6CD127B48ABB00AB900A /* DestinationMetadataPlugin.swift in Sources */,
554-
46A943A029CE162A00D65DC3 /* ObjCPluginSupport.swift in Sources */,
555555
A31A162F2576B73F00C9CDDF /* State.swift in Sources */,
556556
9692726825A583A6009B5298 /* SegmentDestination.swift in Sources */,
557557
4602276C261E7BF900A9E913 /* iOSDelegation.swift in Sources */,
@@ -616,6 +616,7 @@
616616
isa = XCBuildConfiguration;
617617
buildSettings = {
618618
BUILD_LIBRARY_FOR_DISTRIBUTION = YES;
619+
DEAD_CODE_STRIPPING = YES;
619620
ENABLE_TESTABILITY = YES;
620621
FRAMEWORK_SEARCH_PATHS = (
621622
"$(inherited)",
@@ -646,6 +647,7 @@
646647
isa = XCBuildConfiguration;
647648
buildSettings = {
648649
BUILD_LIBRARY_FOR_DISTRIBUTION = YES;
650+
DEAD_CODE_STRIPPING = YES;
649651
ENABLE_TESTABILITY = YES;
650652
FRAMEWORK_SEARCH_PATHS = (
651653
"$(inherited)",
@@ -677,6 +679,7 @@
677679
buildSettings = {
678680
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
679681
CLANG_ENABLE_MODULES = YES;
682+
DEAD_CODE_STRIPPING = YES;
680683
FRAMEWORK_SEARCH_PATHS = (
681684
"$(inherited)",
682685
"$(PLATFORM_DIR)/Developer/Library/Frameworks",
@@ -703,6 +706,7 @@
703706
buildSettings = {
704707
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
705708
CLANG_ENABLE_MODULES = YES;
709+
DEAD_CODE_STRIPPING = YES;
706710
FRAMEWORK_SEARCH_PATHS = (
707711
"$(inherited)",
708712
"$(PLATFORM_DIR)/Developer/Library/Frameworks",
@@ -748,6 +752,7 @@
748752
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
749753
COMBINE_HIDPI_IMAGES = YES;
750754
COPY_PHASE_STRIP = NO;
755+
DEAD_CODE_STRIPPING = YES;
751756
DEBUG_INFORMATION_FORMAT = dwarf;
752757
DYLIB_INSTALL_NAME_BASE = "@rpath";
753758
ENABLE_NS_ASSERTIONS = YES;
@@ -785,6 +790,7 @@
785790
OBJ_37 /* Debug */ = {
786791
isa = XCBuildConfiguration;
787792
buildSettings = {
793+
DEAD_CODE_STRIPPING = YES;
788794
LD = /usr/bin/true;
789795
OTHER_SWIFT_FLAGS = "-swift-version 5 -I $(TOOLCHAIN_DIR)/usr/lib/swift/pm/4_2 -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.0.sdk -package-description-version 5.3.0";
790796
SWIFT_VERSION = 5.0;
@@ -794,6 +800,7 @@
794800
OBJ_38 /* Release */ = {
795801
isa = XCBuildConfiguration;
796802
buildSettings = {
803+
DEAD_CODE_STRIPPING = YES;
797804
LD = /usr/bin/true;
798805
OTHER_SWIFT_FLAGS = "-swift-version 5 -I $(TOOLCHAIN_DIR)/usr/lib/swift/pm/4_2 -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.0.sdk -package-description-version 5.3.0";
799806
SWIFT_VERSION = 5.0;
@@ -824,6 +831,7 @@
824831
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
825832
COMBINE_HIDPI_IMAGES = YES;
826833
COPY_PHASE_STRIP = YES;
834+
DEAD_CODE_STRIPPING = YES;
827835
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
828836
DYLIB_INSTALL_NAME_BASE = "@rpath";
829837
ENABLE_STRICT_OBJC_MSGSEND = YES;
@@ -858,12 +866,14 @@
858866
OBJ_43 /* Debug */ = {
859867
isa = XCBuildConfiguration;
860868
buildSettings = {
869+
DEAD_CODE_STRIPPING = YES;
861870
};
862871
name = Debug;
863872
};
864873
OBJ_44 /* Release */ = {
865874
isa = XCBuildConfiguration;
866875
buildSettings = {
876+
DEAD_CODE_STRIPPING = YES;
867877
};
868878
name = Release;
869879
};

Segment.xcodeproj/xcshareddata/xcschemes/Segment-Package.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1340"
3+
LastUpgradeVersion = "1430"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

0 commit comments

Comments
 (0)