-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Swift-Objective C interoperability (#3)
--------- Co-authored-by: xiaoweii <[email protected]>
- Loading branch information
1 parent
5b95b74
commit 9de9142
Showing
17 changed files
with
271 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import Foundation | ||
|
||
/// ClickstreamAnalytics api for objective-c | ||
@objcMembers public class ClickstreamObjc: NSObject { | ||
/// Init the Clickstream sdk | ||
public static func initSDK() throws { | ||
try ClickstreamAnalytics.initSDK() | ||
} | ||
|
||
/// Use this method to record event | ||
/// - Parameter eventName: the event name | ||
public static func recordEvent(_ eventName: String) { | ||
ClickstreamAnalytics.recordEvent(eventName: eventName) | ||
} | ||
|
||
/// The method to record event with attributes | ||
/// - Parameters: | ||
/// - eventName: the event name | ||
/// - attributes: the event attributes which type is NSDictionary | ||
public static func recordEvent(_ eventName: String, _ attributes: NSDictionary) { | ||
ClickstreamAnalytics.recordEvent(eventName: eventName, attributes: getAttributes(attributes)) | ||
} | ||
|
||
/// Use this method to send events immediately | ||
public static func flushEvents() { | ||
ClickstreamAnalytics.flushEvents() | ||
} | ||
|
||
/// Add global attributes | ||
/// - Parameter attributes: the global attributes to add | ||
public static func addGlobalAttributes(_ attributes: NSDictionary) { | ||
ClickstreamAnalytics.addGlobalAttributes(attributes: getAttributes(attributes)) | ||
} | ||
|
||
/// Delete global attributes | ||
/// - Parameter attributes: the global attributes names to delete | ||
public static func deleteGlobalAttributes(_ attributes: [String]) { | ||
for attribute in attributes { | ||
ClickstreamAnalytics.deleteGlobalAttributes(attributes: attribute) | ||
} | ||
} | ||
|
||
/// Add user attributes | ||
/// - Parameter attributes: the user attributes to add | ||
public static func addUserAttributes(_ attributes: NSDictionary) { | ||
ClickstreamAnalytics.addUserAttributes(attributes: getAttributes(attributes)) | ||
} | ||
|
||
/// Set user id for login and logout | ||
/// - Parameter userId: current userId, nil for logout | ||
public static func setUserId(_ userId: String?) { | ||
ClickstreamAnalytics.setUserId(userId: userId) | ||
} | ||
|
||
/// Get Clickstream configuration, please config it after initialize sdk | ||
/// - Returns: ClickstreamContextConfiguration to modify the configuration of clickstream sdk | ||
public static func getClickstreamConfiguration() throws -> ClickstreamContextConfiguration { | ||
try ClickstreamAnalytics.getClickstreamConfiguration() | ||
} | ||
|
||
private static func getAttributes(_ attributes: NSDictionary) -> ClickstreamAttribute { | ||
var result: ClickstreamAttribute = [:] | ||
for case let (key as String, value) in attributes { | ||
if value is String { | ||
result[key] = value as? String | ||
} else if value is Bool { | ||
if let boolValue = value as? Bool { | ||
result[key] = boolValue ? true : false | ||
} | ||
} else if value is Int { | ||
result[key] = value as? Int | ||
} else if value is Double { | ||
result[key] = value as? Double | ||
} | ||
} | ||
return result | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.