Skip to content

Objective-C API improvements #219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

build_and_test_spm_mac:
needs: cancel_previous
runs-on: macos-11
runs-on: macos-latest
steps:
- uses: maxim-lobanov/setup-xcode@v1
with:
Expand Down Expand Up @@ -48,9 +48,9 @@ jobs:

build_and_test_ios:
needs: cancel_previous
runs-on: macos-11
runs-on: macos-latest
steps:
- uses: maxim-lobanov/setup-xcode@v1.5.1
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest-stable
- uses: actions/checkout@v2
Expand All @@ -62,7 +62,7 @@ jobs:

build_and_test_tvos:
needs: cancel_previous
runs-on: macos-11
runs-on: macos-latest
steps:
- uses: maxim-lobanov/setup-xcode@v1
with:
Expand All @@ -75,7 +75,7 @@ jobs:

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

build_and_test_examples:
needs: cancel_previous
runs-on: macos-12
runs-on: macos-latest
steps:
- uses: maxim-lobanov/setup-xcode@v1.5.1
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest-stable
- uses: actions/checkout@v2
Expand Down
44 changes: 33 additions & 11 deletions Examples/apps/ObjCExample/ObjCExample/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ @implementation AppDelegate

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

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

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

[self.analytics addSourceMiddleware:^NSDictionary<NSString *,id> * _Nullable(NSDictionary<NSString *,id> * _Nullable event) {
// drop all events named booya
NSString *eventType = event[@"type"];
if ([eventType isEqualToString:@"track"]) {
NSString *eventName = event[@"event"];
if ([eventName isEqualToString:@"booya"]) {
return nil;
}
SEGBlockPlugin *customizeAllTrackCalls = [[SEGBlockPlugin alloc] initWithBlock:^id<SEGRawEvent> _Nullable(id<SEGRawEvent> _Nullable event) {
if ([event isKindOfClass: [SEGTrackEvent class]]) {
SEGTrackEvent *track = (SEGTrackEvent *)event;
// change the name
NSString *newName = [NSString stringWithFormat: @"[New] %@", track.event];
track.event = newName;
// add a property
NSMutableDictionary *newProps = (track.properties != nil) ? [track.properties mutableCopy] : [@{} mutableCopy];
newProps[@"customAttribute"] = @"Hello";
track.properties = newProps;

return track;
}
return event;
}];

//[self.analytics addDestination:[[SEGMixpanelDestination alloc] init]];
[self.analytics addPlugin:customizeAllTrackCalls];

SEGBlockPlugin *booyaAllTrackCalls = [[SEGBlockPlugin alloc] initWithBlock:^id<SEGRawEvent> _Nullable(id<SEGRawEvent> _Nullable event) {
if ([event isKindOfClass: [SEGTrackEvent class]]) {
SEGTrackEvent *track = (SEGTrackEvent *)event;
// change the name
NSString *newName = [NSString stringWithFormat: @"[Booya] %@", track.event];
track.event = newName;
// add a property
NSMutableDictionary *newProps = (track.properties != nil) ? [track.properties mutableCopy] : [@{} mutableCopy];
newProps[@"customAttribute"] = @"Booya!";
track.properties = newProps;

return track;
}
return event;
}];

[self.analytics addPlugin:booyaAllTrackCalls destinationKey:@"Segment.io"];

dispatch_async(dispatch_get_main_queue(), ^{
[self.analytics track:@"booya"];
[self.analytics track:@"schneeble schnobble"];
});

return YES;
Expand Down
14 changes: 12 additions & 2 deletions Examples/apps/ObjCExample/ObjCExample/TestDestination.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,18 @@ public class TestDestination: DestinationPlugin {
public let type = PluginType.destination
public var analytics: Analytics? = nil

public func execute<T: RawEvent>(event: T?) -> T? {
print("some event came to visit us for xmas din din.")
public func configure(analytics: Analytics) {
analytics.manuallyEnableDestination(plugin: self)
self.analytics = analytics
}

public func update(settings: Settings, type: UpdateType) {
// analytics?.manuallyEnableDestination(plugin: self)
}

public func track(event: TrackEvent) -> TrackEvent? {
print("Event Received: \n")
print(event.prettyPrint())
return event
}
}
28 changes: 19 additions & 9 deletions Segment.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
465879BB2686560C00180335 /* watchOSLifecycleMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 465879B92686560C00180335 /* watchOSLifecycleMonitor.swift */; };
4663C729267A799100ADDD1A /* QueueTimer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4663C728267A799100ADDD1A /* QueueTimer.swift */; };
466EC2CE28FB7D5D001B384E /* OutputFileStream.swift in Sources */ = {isa = PBXBuildFile; fileRef = 466EC2CD28FB7D5D001B384E /* OutputFileStream.swift */; };
4689231329F7391500AB26E5 /* ObjCPlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4689231129F7391500AB26E5 /* ObjCPlugin.swift */; };
4689231429F7391500AB26E5 /* ObjCEvents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4689231229F7391500AB26E5 /* ObjCEvents.swift */; };
4697A238290341EF00FAE14F /* Errors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4697A237290341EF00FAE14F /* Errors.swift */; };
46A018C225E5857D00F9CCD8 /* Context.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46A018C125E5857D00F9CCD8 /* Context.swift */; };
46A018D425E6C9C200F9CCD8 /* LinuxUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46A018D325E6C9C200F9CCD8 /* LinuxUtils.swift */; };
46A018DA25E97FDF00F9CCD8 /* AppleUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46A018D925E97FDF00F9CCD8 /* AppleUtils.swift */; };
46A018EE25E9A74F00F9CCD8 /* VendorSystem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46A018ED25E9A74F00F9CCD8 /* VendorSystem.swift */; };
46A9439F29CE162A00D65DC3 /* ObjCDestinationSupport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46A9439D29CE162A00D65DC3 /* ObjCDestinationSupport.swift */; };
46A943A029CE162A00D65DC3 /* ObjCPluginSupport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46A9439E29CE162A00D65DC3 /* ObjCPluginSupport.swift */; };
46B1AC6927346D3D00846DE8 /* StressTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46B1AC6827346D3D00846DE8 /* StressTests.swift */; };
46E382E72654429A00BA2502 /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46E382E62654429A00BA2502 /* Utils.swift */; };
46F7485D26C718710042798E /* ObjCAnalytics.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46F7485B26C718710042798E /* ObjCAnalytics.swift */; };
Expand Down Expand Up @@ -125,13 +125,13 @@
465879B92686560C00180335 /* watchOSLifecycleMonitor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = watchOSLifecycleMonitor.swift; sourceTree = "<group>"; };
4663C728267A799100ADDD1A /* QueueTimer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QueueTimer.swift; sourceTree = "<group>"; };
466EC2CD28FB7D5D001B384E /* OutputFileStream.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OutputFileStream.swift; sourceTree = "<group>"; };
4689231129F7391500AB26E5 /* ObjCPlugin.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObjCPlugin.swift; sourceTree = "<group>"; };
4689231229F7391500AB26E5 /* ObjCEvents.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObjCEvents.swift; sourceTree = "<group>"; };
4697A237290341EF00FAE14F /* Errors.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Errors.swift; sourceTree = "<group>"; };
46A018C125E5857D00F9CCD8 /* Context.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Context.swift; sourceTree = "<group>"; };
46A018D325E6C9C200F9CCD8 /* LinuxUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinuxUtils.swift; sourceTree = "<group>"; };
46A018D925E97FDF00F9CCD8 /* AppleUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleUtils.swift; sourceTree = "<group>"; };
46A018ED25E9A74F00F9CCD8 /* VendorSystem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VendorSystem.swift; sourceTree = "<group>"; };
46A9439D29CE162A00D65DC3 /* ObjCDestinationSupport.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObjCDestinationSupport.swift; sourceTree = "<group>"; };
46A9439E29CE162A00D65DC3 /* ObjCPluginSupport.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObjCPluginSupport.swift; sourceTree = "<group>"; };
46B1AC6827346D3D00846DE8 /* StressTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StressTests.swift; sourceTree = "<group>"; };
46D98E3D26D6FEF300E7A86A /* FlurryDestination.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlurryDestination.swift; sourceTree = "<group>"; };
46D98E3E26D6FEF300E7A86A /* AdjustDestination.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdjustDestination.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -223,9 +223,9 @@
isa = PBXGroup;
children = (
46F7485B26C718710042798E /* ObjCAnalytics.swift */,
4689231229F7391500AB26E5 /* ObjCEvents.swift */,
4689231129F7391500AB26E5 /* ObjCPlugin.swift */,
46F7485C26C718710042798E /* ObjCConfiguration.swift */,
46A9439D29CE162A00D65DC3 /* ObjCDestinationSupport.swift */,
46A9439E29CE162A00D65DC3 /* ObjCPluginSupport.swift */,
);
path = ObjC;
sourceTree = "<group>";
Expand Down Expand Up @@ -493,7 +493,7 @@
attributes = {
LastSwiftMigration = 9999;
LastSwiftUpdateCheck = 1220;
LastUpgradeCheck = 1340;
LastUpgradeCheck = 1430;
};
buildConfigurationList = OBJ_2 /* Build configuration list for PBXProject "Segment" */;
compatibilityVersion = "Xcode 3.2";
Expand Down Expand Up @@ -531,7 +531,6 @@
46022764261E64A800A9E913 /* iOSLifecycleEvents.swift in Sources */,
96A9624E2810C6B80011DE54 /* macOSLifecycleEvents.swift in Sources */,
460FF30B29BA525900635FF9 /* Logging.swift in Sources */,
46A9439F29CE162A00D65DC3 /* ObjCDestinationSupport.swift in Sources */,
4621080C2605332D00EBC4A8 /* KeyPath.swift in Sources */,
A31A16262576B6F200C9CDDF /* Timeline.swift in Sources */,
96C33AB1258961F500F3D538 /* Settings.swift in Sources */,
Expand All @@ -543,15 +542,16 @@
OBJ_23 /* Analytics.swift in Sources */,
A31A16342576B7AF00C9CDDF /* Types.swift in Sources */,
46A018DA25E97FDF00F9CCD8 /* AppleUtils.swift in Sources */,
4689231429F7391500AB26E5 /* ObjCEvents.swift in Sources */,
A31A16E12579779600C9CDDF /* Version.swift in Sources */,
46210836260BBEE400EBC4A8 /* DeviceToken.swift in Sources */,
9692724E25A4E5B7009B5298 /* Startup.swift in Sources */,
4663C729267A799100ADDD1A /* QueueTimer.swift in Sources */,
4689231329F7391500AB26E5 /* ObjCPlugin.swift in Sources */,
46FE4C9C25A3F41C003A7362 /* LinuxLifecycleMonitor.swift in Sources */,
460227422612987300A9E913 /* watchOSLifecycleEvents.swift in Sources */,
46F7485E26C718710042798E /* ObjCConfiguration.swift in Sources */,
759D6CD127B48ABB00AB900A /* DestinationMetadataPlugin.swift in Sources */,
46A943A029CE162A00D65DC3 /* ObjCPluginSupport.swift in Sources */,
A31A162F2576B73F00C9CDDF /* State.swift in Sources */,
9692726825A583A6009B5298 /* SegmentDestination.swift in Sources */,
4602276C261E7BF900A9E913 /* iOSDelegation.swift in Sources */,
Expand Down Expand Up @@ -616,6 +616,7 @@
isa = XCBuildConfiguration;
buildSettings = {
BUILD_LIBRARY_FOR_DISTRIBUTION = YES;
DEAD_CODE_STRIPPING = YES;
ENABLE_TESTABILITY = YES;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand Down Expand Up @@ -646,6 +647,7 @@
isa = XCBuildConfiguration;
buildSettings = {
BUILD_LIBRARY_FOR_DISTRIBUTION = YES;
DEAD_CODE_STRIPPING = YES;
ENABLE_TESTABILITY = YES;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand Down Expand Up @@ -677,6 +679,7 @@
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CLANG_ENABLE_MODULES = YES;
DEAD_CODE_STRIPPING = YES;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PLATFORM_DIR)/Developer/Library/Frameworks",
Expand All @@ -703,6 +706,7 @@
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CLANG_ENABLE_MODULES = YES;
DEAD_CODE_STRIPPING = YES;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PLATFORM_DIR)/Developer/Library/Frameworks",
Expand Down Expand Up @@ -748,6 +752,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = dwarf;
DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_NS_ASSERTIONS = YES;
Expand Down Expand Up @@ -785,6 +790,7 @@
OBJ_37 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
DEAD_CODE_STRIPPING = YES;
LD = /usr/bin/true;
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";
SWIFT_VERSION = 5.0;
Expand All @@ -794,6 +800,7 @@
OBJ_38 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
DEAD_CODE_STRIPPING = YES;
LD = /usr/bin/true;
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";
SWIFT_VERSION = 5.0;
Expand Down Expand Up @@ -824,6 +831,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = YES;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand Down Expand Up @@ -858,12 +866,14 @@
OBJ_43 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
DEAD_CODE_STRIPPING = YES;
};
name = Debug;
};
OBJ_44 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
DEAD_CODE_STRIPPING = YES;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1340"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Loading