diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..9e49d73 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,45 @@ +name: CI + +on: + push: + branches: [main, develop] + pull_request: + branches: [main, develop] + +jobs: + build-and-test: + name: Build and Test + runs-on: macos-14 + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Select Xcode version + run: sudo xcode-select -switch /Applications/Xcode_15.2.app + + - name: Show versions + run: | + xcodebuild -version + swift --version + + - name: Resolve dependencies + run: swift package resolve + + - name: Build for iOS Simulator + run: | + xcodebuild build-for-testing \ + -scheme Knock \ + -sdk iphonesimulator \ + -destination 'platform=iOS Simulator,name=iPhone 15,OS=17.2' \ + CODE_SIGN_IDENTITY="" \ + CODE_SIGNING_REQUIRED=NO \ + ONLY_ACTIVE_ARCH=NO + + - name: Run tests + run: | + xcodebuild test-without-building \ + -scheme Knock \ + -sdk iphonesimulator \ + -destination 'platform=iOS Simulator,name=iPhone 15,OS=17.2' \ + -enableCodeCoverage YES diff --git a/.gitignore b/.gitignore index 41636c7..7dd7661 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ DerivedData/ .swiftpm/config/registries.json .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata .netrc -LocalHelp.md \ No newline at end of file +LocalHelp.md +*.xcodeproj \ No newline at end of file diff --git a/Knock.podspec b/Knock.podspec index e79ed26..bb6010a 100644 --- a/Knock.podspec +++ b/Knock.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = "Knock" - spec.version = "1.2.5" + spec.version = "1.2.6" spec.summary = "An SDK to build in-app notifications experiences in Swift with Knock." spec.description = <<-DESC diff --git a/Knock.xcodeproj/project.pbxproj b/Knock.xcodeproj/project.pbxproj deleted file mode 100644 index 7ffbe38..0000000 --- a/Knock.xcodeproj/project.pbxproj +++ /dev/null @@ -1,583 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 56; - objects = { - -/* Begin PBXBuildFile section */ - F1356CDF2A4370C4007891B1 /* Push.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1356CD42A4370C4007891B1 /* Push.swift */; }; - F1356CE02A4370C4007891B1 /* Defaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1356CD52A4370C4007891B1 /* Defaults.swift */; }; - F1356CE12A4370C4007891B1 /* PhoenixTransport.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1356CD62A4370C4007891B1 /* PhoenixTransport.swift */; }; - F1356CE22A4370C4007891B1 /* Delegated.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1356CD72A4370C4007891B1 /* Delegated.swift */; }; - F1356CE32A4370C4007891B1 /* Presence.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1356CD82A4370C4007891B1 /* Presence.swift */; }; - F1356CE42A4370C4007891B1 /* Message.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1356CD92A4370C4007891B1 /* Message.swift */; }; - F1356CE52A4370C4007891B1 /* Socket.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1356CDA2A4370C4007891B1 /* Socket.swift */; }; - F1356CE62A4370C4007891B1 /* Channel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1356CDB2A4370C4007891B1 /* Channel.swift */; }; - F1356CE72A4370C4007891B1 /* TimeoutTimer.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1356CDC2A4370C4007891B1 /* TimeoutTimer.swift */; }; - F1356CE82A4370C4007891B1 /* HeartbeatTimer.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1356CDD2A4370C4007891B1 /* HeartbeatTimer.swift */; }; - F1356CE92A4370C4007891B1 /* SynchronizedArray.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1356CDE2A4370C4007891B1 /* SynchronizedArray.swift */; }; - F16684DB2A413E2B0037A2E9 /* Knock.docc in Sources */ = {isa = PBXBuildFile; fileRef = F16684DA2A413E2B0037A2E9 /* Knock.docc */; }; - F16684E12A413E2B0037A2E9 /* Knock.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F16684D62A413E2B0037A2E9 /* Knock.framework */; }; - F16684E62A413E2B0037A2E9 /* KnockTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F16684E52A413E2B0037A2E9 /* KnockTests.swift */; }; - F16684F32A4140110037A2E9 /* LICENSE.md in Resources */ = {isa = PBXBuildFile; fileRef = F16684F22A4140110037A2E9 /* LICENSE.md */; }; - F16684F52A4140260037A2E9 /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = F16684F42A4140260037A2E9 /* README.md */; }; - F16684F92A4209C60037A2E9 /* Knock.swift in Sources */ = {isa = PBXBuildFile; fileRef = F16684F82A4209C50037A2E9 /* Knock.swift */; }; - F16685012A4209DE0037A2E9 /* Either.swift in Sources */ = {isa = PBXBuildFile; fileRef = F16684FA2A4209DE0037A2E9 /* Either.swift */; }; - F16685022A4209DE0037A2E9 /* KnockAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = F16685002A4209DE0037A2E9 /* KnockAPI.swift */; }; - F16685032A4209DE0037A2E9 /* KnockMessages.swift in Sources */ = {isa = PBXBuildFile; fileRef = F16684FB2A4209DE0037A2E9 /* KnockMessages.swift */; }; - F16685042A4209DE0037A2E9 /* KnockPreferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = F16684FF2A4209DE0037A2E9 /* KnockPreferences.swift */; }; - F16685052A4209DE0037A2E9 /* KnockChannels.swift in Sources */ = {isa = PBXBuildFile; fileRef = F16684FC2A4209DE0037A2E9 /* KnockChannels.swift */; }; - F16685062A4209DE0037A2E9 /* KnockFeed.swift in Sources */ = {isa = PBXBuildFile; fileRef = F16684FD2A4209DE0037A2E9 /* KnockFeed.swift */; }; - F16685072A4209DE0037A2E9 /* KnockUsers.swift in Sources */ = {isa = PBXBuildFile; fileRef = F16684FE2A4209DE0037A2E9 /* KnockUsers.swift */; }; - F1EB123D2A4368740015BE31 /* AnyCodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1EB123A2A4368740015BE31 /* AnyCodable.swift */; }; - F1EB123E2A4368740015BE31 /* AnyDecodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1EB123B2A4368740015BE31 /* AnyDecodable.swift */; }; - F1EB123F2A4368740015BE31 /* AnyEncodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1EB123C2A4368740015BE31 /* AnyEncodable.swift */; }; -/* End PBXBuildFile section */ - -/* Begin PBXContainerItemProxy section */ - F16684E22A413E2B0037A2E9 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = F16684CD2A413E2B0037A2E9 /* Project object */; - proxyType = 1; - remoteGlobalIDString = F16684D52A413E2B0037A2E9; - remoteInfo = Knock; - }; -/* End PBXContainerItemProxy section */ - -/* Begin PBXFileReference section */ - F1356CD42A4370C4007891B1 /* Push.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Push.swift; sourceTree = ""; }; - F1356CD52A4370C4007891B1 /* Defaults.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Defaults.swift; sourceTree = ""; }; - F1356CD62A4370C4007891B1 /* PhoenixTransport.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhoenixTransport.swift; sourceTree = ""; }; - F1356CD72A4370C4007891B1 /* Delegated.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Delegated.swift; sourceTree = ""; }; - F1356CD82A4370C4007891B1 /* Presence.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Presence.swift; sourceTree = ""; }; - F1356CD92A4370C4007891B1 /* Message.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Message.swift; sourceTree = ""; }; - F1356CDA2A4370C4007891B1 /* Socket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Socket.swift; sourceTree = ""; }; - F1356CDB2A4370C4007891B1 /* Channel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Channel.swift; sourceTree = ""; }; - F1356CDC2A4370C4007891B1 /* TimeoutTimer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TimeoutTimer.swift; sourceTree = ""; }; - F1356CDD2A4370C4007891B1 /* HeartbeatTimer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HeartbeatTimer.swift; sourceTree = ""; }; - F1356CDE2A4370C4007891B1 /* SynchronizedArray.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SynchronizedArray.swift; sourceTree = ""; }; - F1356CEA2A4370CF007891B1 /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = ""; }; - F16684D62A413E2B0037A2E9 /* Knock.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Knock.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - F16684DA2A413E2B0037A2E9 /* Knock.docc */ = {isa = PBXFileReference; lastKnownFileType = folder.documentationcatalog; path = Knock.docc; sourceTree = ""; }; - F16684E02A413E2B0037A2E9 /* KnockTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = KnockTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - F16684E52A413E2B0037A2E9 /* KnockTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KnockTests.swift; sourceTree = ""; }; - F16684F22A4140110037A2E9 /* LICENSE.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = LICENSE.md; sourceTree = ""; }; - F16684F42A4140260037A2E9 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; - F16684F82A4209C50037A2E9 /* Knock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Knock.swift; sourceTree = ""; }; - F16684FA2A4209DE0037A2E9 /* Either.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Either.swift; sourceTree = ""; }; - F16684FB2A4209DE0037A2E9 /* KnockMessages.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KnockMessages.swift; sourceTree = ""; }; - F16684FC2A4209DE0037A2E9 /* KnockChannels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KnockChannels.swift; sourceTree = ""; }; - F16684FD2A4209DE0037A2E9 /* KnockFeed.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KnockFeed.swift; sourceTree = ""; }; - F16684FE2A4209DE0037A2E9 /* KnockUsers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KnockUsers.swift; sourceTree = ""; }; - F16684FF2A4209DE0037A2E9 /* KnockPreferences.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KnockPreferences.swift; sourceTree = ""; }; - F16685002A4209DE0037A2E9 /* KnockAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KnockAPI.swift; sourceTree = ""; }; - F1EB123A2A4368740015BE31 /* AnyCodable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnyCodable.swift; sourceTree = ""; }; - F1EB123B2A4368740015BE31 /* AnyDecodable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnyDecodable.swift; sourceTree = ""; }; - F1EB123C2A4368740015BE31 /* AnyEncodable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnyEncodable.swift; sourceTree = ""; }; - F1EB12402A4368880015BE31 /* LICENSE.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = LICENSE.md; sourceTree = ""; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - F16684D32A413E2B0037A2E9 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; - F16684DD2A413E2B0037A2E9 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - F16684E12A413E2B0037A2E9 /* Knock.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - F1356CD32A4370A8007891B1 /* SwiftPhoenixClient */ = { - isa = PBXGroup; - children = ( - F1356CEA2A4370CF007891B1 /* LICENSE */, - F1356CDB2A4370C4007891B1 /* Channel.swift */, - F1356CD52A4370C4007891B1 /* Defaults.swift */, - F1356CD72A4370C4007891B1 /* Delegated.swift */, - F1356CDD2A4370C4007891B1 /* HeartbeatTimer.swift */, - F1356CD92A4370C4007891B1 /* Message.swift */, - F1356CD62A4370C4007891B1 /* PhoenixTransport.swift */, - F1356CD82A4370C4007891B1 /* Presence.swift */, - F1356CD42A4370C4007891B1 /* Push.swift */, - F1356CDA2A4370C4007891B1 /* Socket.swift */, - F1356CDE2A4370C4007891B1 /* SynchronizedArray.swift */, - F1356CDC2A4370C4007891B1 /* TimeoutTimer.swift */, - ); - path = SwiftPhoenixClient; - sourceTree = ""; - }; - F16684CC2A413E2B0037A2E9 = { - isa = PBXGroup; - children = ( - F16685102A420D490037A2E9 /* Sources */, - F16684F22A4140110037A2E9 /* LICENSE.md */, - F16684F42A4140260037A2E9 /* README.md */, - F16684DA2A413E2B0037A2E9 /* Knock.docc */, - F16684E42A413E2B0037A2E9 /* KnockTests */, - F16684D72A413E2B0037A2E9 /* Products */, - ); - sourceTree = ""; - }; - F16684D72A413E2B0037A2E9 /* Products */ = { - isa = PBXGroup; - children = ( - F16684D62A413E2B0037A2E9 /* Knock.framework */, - F16684E02A413E2B0037A2E9 /* KnockTests.xctest */, - ); - name = Products; - sourceTree = ""; - }; - F16684E42A413E2B0037A2E9 /* KnockTests */ = { - isa = PBXGroup; - children = ( - F16684E52A413E2B0037A2E9 /* KnockTests.swift */, - ); - path = KnockTests; - sourceTree = ""; - }; - F16685102A420D490037A2E9 /* Sources */ = { - isa = PBXGroup; - children = ( - F1356CD32A4370A8007891B1 /* SwiftPhoenixClient */, - F1EB12392A4368530015BE31 /* AnyCodable */, - F16684FA2A4209DE0037A2E9 /* Either.swift */, - F16684F82A4209C50037A2E9 /* Knock.swift */, - F16685002A4209DE0037A2E9 /* KnockAPI.swift */, - F16684FC2A4209DE0037A2E9 /* KnockChannels.swift */, - F16684FD2A4209DE0037A2E9 /* KnockFeed.swift */, - F16684FB2A4209DE0037A2E9 /* KnockMessages.swift */, - F16684FF2A4209DE0037A2E9 /* KnockPreferences.swift */, - F16684FE2A4209DE0037A2E9 /* KnockUsers.swift */, - ); - path = Sources; - sourceTree = ""; - }; - F1EB12392A4368530015BE31 /* AnyCodable */ = { - isa = PBXGroup; - children = ( - F1EB12402A4368880015BE31 /* LICENSE.md */, - F1EB123A2A4368740015BE31 /* AnyCodable.swift */, - F1EB123B2A4368740015BE31 /* AnyDecodable.swift */, - F1EB123C2A4368740015BE31 /* AnyEncodable.swift */, - ); - path = AnyCodable; - sourceTree = ""; - }; -/* End PBXGroup section */ - -/* Begin PBXHeadersBuildPhase section */ - F16684D12A413E2B0037A2E9 /* Headers */ = { - isa = PBXHeadersBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXHeadersBuildPhase section */ - -/* Begin PBXNativeTarget section */ - F16684D52A413E2B0037A2E9 /* Knock */ = { - isa = PBXNativeTarget; - buildConfigurationList = F16684EA2A413E2B0037A2E9 /* Build configuration list for PBXNativeTarget "Knock" */; - buildPhases = ( - F16684D12A413E2B0037A2E9 /* Headers */, - F16684D22A413E2B0037A2E9 /* Sources */, - F16684D32A413E2B0037A2E9 /* Frameworks */, - F16684D42A413E2B0037A2E9 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = Knock; - packageProductDependencies = ( - ); - productName = Knock; - productReference = F16684D62A413E2B0037A2E9 /* Knock.framework */; - productType = "com.apple.product-type.framework"; - }; - F16684DF2A413E2B0037A2E9 /* KnockTests */ = { - isa = PBXNativeTarget; - buildConfigurationList = F16684ED2A413E2B0037A2E9 /* Build configuration list for PBXNativeTarget "KnockTests" */; - buildPhases = ( - F16684DC2A413E2B0037A2E9 /* Sources */, - F16684DD2A413E2B0037A2E9 /* Frameworks */, - F16684DE2A413E2B0037A2E9 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - F16684E32A413E2B0037A2E9 /* PBXTargetDependency */, - ); - name = KnockTests; - productName = KnockTests; - productReference = F16684E02A413E2B0037A2E9 /* KnockTests.xctest */; - productType = "com.apple.product-type.bundle.unit-test"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - F16684CD2A413E2B0037A2E9 /* Project object */ = { - isa = PBXProject; - attributes = { - BuildIndependentTargetsInParallel = 1; - LastSwiftUpdateCheck = 1430; - LastUpgradeCheck = 1430; - TargetAttributes = { - F16684D52A413E2B0037A2E9 = { - CreatedOnToolsVersion = 14.3.1; - }; - F16684DF2A413E2B0037A2E9 = { - CreatedOnToolsVersion = 14.3.1; - }; - }; - }; - buildConfigurationList = F16684D02A413E2B0037A2E9 /* Build configuration list for PBXProject "Knock" */; - compatibilityVersion = "Xcode 14.0"; - developmentRegion = en; - hasScannedForEncodings = 0; - knownRegions = ( - en, - Base, - ); - mainGroup = F16684CC2A413E2B0037A2E9; - packageReferences = ( - ); - productRefGroup = F16684D72A413E2B0037A2E9 /* Products */; - projectDirPath = ""; - projectRoot = ""; - targets = ( - F16684D52A413E2B0037A2E9 /* Knock */, - F16684DF2A413E2B0037A2E9 /* KnockTests */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXResourcesBuildPhase section */ - F16684D42A413E2B0037A2E9 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - F16684F52A4140260037A2E9 /* README.md in Resources */, - F16684F32A4140110037A2E9 /* LICENSE.md in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - F16684DE2A413E2B0037A2E9 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXResourcesBuildPhase section */ - -/* Begin PBXSourcesBuildPhase section */ - F16684D22A413E2B0037A2E9 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - F16685072A4209DE0037A2E9 /* KnockUsers.swift in Sources */, - F1356CE62A4370C4007891B1 /* Channel.swift in Sources */, - F1356CE32A4370C4007891B1 /* Presence.swift in Sources */, - F1356CE12A4370C4007891B1 /* PhoenixTransport.swift in Sources */, - F1356CE42A4370C4007891B1 /* Message.swift in Sources */, - F1356CE02A4370C4007891B1 /* Defaults.swift in Sources */, - F16684F92A4209C60037A2E9 /* Knock.swift in Sources */, - F1356CE72A4370C4007891B1 /* TimeoutTimer.swift in Sources */, - F16685022A4209DE0037A2E9 /* KnockAPI.swift in Sources */, - F16685032A4209DE0037A2E9 /* KnockMessages.swift in Sources */, - F1356CE52A4370C4007891B1 /* Socket.swift in Sources */, - F16685012A4209DE0037A2E9 /* Either.swift in Sources */, - F16685062A4209DE0037A2E9 /* KnockFeed.swift in Sources */, - F16685052A4209DE0037A2E9 /* KnockChannels.swift in Sources */, - F1356CE82A4370C4007891B1 /* HeartbeatTimer.swift in Sources */, - F1356CE22A4370C4007891B1 /* Delegated.swift in Sources */, - F1EB123D2A4368740015BE31 /* AnyCodable.swift in Sources */, - F1356CDF2A4370C4007891B1 /* Push.swift in Sources */, - F1356CE92A4370C4007891B1 /* SynchronizedArray.swift in Sources */, - F16684DB2A413E2B0037A2E9 /* Knock.docc in Sources */, - F16685042A4209DE0037A2E9 /* KnockPreferences.swift in Sources */, - F1EB123F2A4368740015BE31 /* AnyEncodable.swift in Sources */, - F1EB123E2A4368740015BE31 /* AnyDecodable.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - F16684DC2A413E2B0037A2E9 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - F16684E62A413E2B0037A2E9 /* KnockTests.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin PBXTargetDependency section */ - F16684E32A413E2B0037A2E9 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = F16684D52A413E2B0037A2E9 /* Knock */; - targetProxy = F16684E22A413E2B0037A2E9 /* PBXContainerItemProxy */; - }; -/* End PBXTargetDependency section */ - -/* Begin XCBuildConfiguration section */ - F16684E82A413E2B0037A2E9 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_ANALYZER_NONNULL = YES; - CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_ENABLE_OBJC_WEAK = YES; - CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_COMMA = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_DOCUMENTATION_COMMENTS = YES; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; - CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; - CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; - CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; - CLANG_WARN_STRICT_PROTOTYPES = YES; - CLANG_WARN_SUSPICIOUS_MOVE = YES; - CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 1; - DEBUG_INFORMATION_FORMAT = dwarf; - ENABLE_STRICT_OBJC_MSGSEND = YES; - ENABLE_TESTABILITY = YES; - GCC_C_LANGUAGE_STANDARD = gnu11; - GCC_DYNAMIC_NO_PIC = NO; - GCC_NO_COMMON_BLOCKS = YES; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 16.4; - MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; - MTL_FAST_MATH = YES; - ONLY_ACTIVE_ARCH = YES; - SDKROOT = iphoneos; - SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - VERSIONING_SYSTEM = "apple-generic"; - VERSION_INFO_PREFIX = ""; - }; - name = Debug; - }; - F16684E92A413E2B0037A2E9 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_ANALYZER_NONNULL = YES; - CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_ENABLE_OBJC_WEAK = YES; - CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_COMMA = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_DOCUMENTATION_COMMENTS = YES; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; - CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; - CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; - CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; - CLANG_WARN_STRICT_PROTOTYPES = YES; - CLANG_WARN_SUSPICIOUS_MOVE = YES; - CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 1; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - ENABLE_NS_ASSERTIONS = NO; - ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_C_LANGUAGE_STANDARD = gnu11; - GCC_NO_COMMON_BLOCKS = YES; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 16.4; - MTL_ENABLE_DEBUG_INFO = NO; - MTL_FAST_MATH = YES; - SDKROOT = iphoneos; - SWIFT_COMPILATION_MODE = wholemodule; - SWIFT_OPTIMIZATION_LEVEL = "-O"; - VALIDATE_PRODUCT = YES; - VERSIONING_SYSTEM = "apple-generic"; - VERSION_INFO_PREFIX = ""; - }; - name = Release; - }; - F16684EB2A413E2B0037A2E9 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 1; - DEFINES_MODULE = YES; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - ENABLE_MODULE_VERIFIER = YES; - GENERATE_INFOPLIST_FILE = YES; - INFOPLIST_KEY_NSHumanReadableCopyright = ""; - INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 16.0; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); - MARKETING_VERSION = 1.0; - MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++"; - MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++20"; - PRODUCT_BUNDLE_IDENTIFIER = app.knock.sdk.Knock; - PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; - SKIP_INSTALL = YES; - SWIFT_EMIT_LOC_STRINGS = YES; - SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2"; - }; - name = Debug; - }; - F16684EC2A413E2B0037A2E9 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 1; - DEFINES_MODULE = YES; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - ENABLE_MODULE_VERIFIER = YES; - GENERATE_INFOPLIST_FILE = YES; - INFOPLIST_KEY_NSHumanReadableCopyright = ""; - INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 16.0; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); - MARKETING_VERSION = 1.0; - MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++"; - MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++20"; - PRODUCT_BUNDLE_IDENTIFIER = app.knock.sdk.Knock; - PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; - SKIP_INSTALL = YES; - SWIFT_EMIT_LOC_STRINGS = YES; - SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2"; - }; - name = Release; - }; - F16684EE2A413E2B0037A2E9 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; - CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 1; - GENERATE_INFOPLIST_FILE = YES; - MARKETING_VERSION = 1.0; - PRODUCT_BUNDLE_IDENTIFIER = app.knock.sdk.KnockTests; - PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_EMIT_LOC_STRINGS = NO; - SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2"; - }; - name = Debug; - }; - F16684EF2A413E2B0037A2E9 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; - CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 1; - GENERATE_INFOPLIST_FILE = YES; - MARKETING_VERSION = 1.0; - PRODUCT_BUNDLE_IDENTIFIER = app.knock.sdk.KnockTests; - PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_EMIT_LOC_STRINGS = NO; - SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2"; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - F16684D02A413E2B0037A2E9 /* Build configuration list for PBXProject "Knock" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - F16684E82A413E2B0037A2E9 /* Debug */, - F16684E92A413E2B0037A2E9 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - F16684EA2A413E2B0037A2E9 /* Build configuration list for PBXNativeTarget "Knock" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - F16684EB2A413E2B0037A2E9 /* Debug */, - F16684EC2A413E2B0037A2E9 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - F16684ED2A413E2B0037A2E9 /* Build configuration list for PBXNativeTarget "KnockTests" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - F16684EE2A413E2B0037A2E9 /* Debug */, - F16684EF2A413E2B0037A2E9 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - }; - rootObject = F16684CD2A413E2B0037A2E9 /* Project object */; -} diff --git a/Knock.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Knock.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist deleted file mode 100644 index 18d9810..0000000 --- a/Knock.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +++ /dev/null @@ -1,8 +0,0 @@ - - - - - IDEDidComputeMac32BitWarning - - - diff --git a/Knock.xcodeproj/xcshareddata/xcbaselines/F16684DF2A413E2B0037A2E9.xcbaseline/18EDA537-0560-4A88-955C-F7523FEB569E.plist b/Knock.xcodeproj/xcshareddata/xcbaselines/F16684DF2A413E2B0037A2E9.xcbaseline/18EDA537-0560-4A88-955C-F7523FEB569E.plist deleted file mode 100644 index ba27016..0000000 --- a/Knock.xcodeproj/xcshareddata/xcbaselines/F16684DF2A413E2B0037A2E9.xcbaseline/18EDA537-0560-4A88-955C-F7523FEB569E.plist +++ /dev/null @@ -1,22 +0,0 @@ - - - - - classNames - - KnockTests - - testPerformanceExample() - - com.apple.XCTPerformanceMetric_WallClockTime - - baselineAverage - 0.000064 - baselineIntegrationDisplayName - Local Baseline - - - - - - diff --git a/Knock.xcodeproj/xcshareddata/xcbaselines/F16684DF2A413E2B0037A2E9.xcbaseline/Info.plist b/Knock.xcodeproj/xcshareddata/xcbaselines/F16684DF2A413E2B0037A2E9.xcbaseline/Info.plist deleted file mode 100644 index a64f41d..0000000 --- a/Knock.xcodeproj/xcshareddata/xcbaselines/F16684DF2A413E2B0037A2E9.xcbaseline/Info.plist +++ /dev/null @@ -1,40 +0,0 @@ - - - - - runDestinationsByUUID - - 18EDA537-0560-4A88-955C-F7523FEB569E - - localComputer - - busSpeedInMHz - 0 - cpuCount - 1 - cpuKind - Apple M1 - cpuSpeedInMHz - 0 - logicalCPUCoresPerPackage - 8 - modelCode - Macmini9,1 - physicalCPUCoresPerPackage - 8 - platformIdentifier - com.apple.platform.macosx - - targetArchitecture - arm64 - targetDevice - - modelCode - iPhone15,2 - platformIdentifier - com.apple.platform.iphonesimulator - - - - - diff --git a/Knock.xcodeproj/xcshareddata/xcschemes/Knock 1.xcscheme b/Knock.xcodeproj/xcshareddata/xcschemes/Knock 1.xcscheme deleted file mode 100644 index e238cc1..0000000 --- a/Knock.xcodeproj/xcshareddata/xcschemes/Knock 1.xcscheme +++ /dev/null @@ -1,66 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Knock.xcodeproj/xcshareddata/xcschemes/Knock.xcscheme b/Knock.xcodeproj/xcshareddata/xcschemes/Knock.xcscheme deleted file mode 100644 index 00bcf1a..0000000 --- a/Knock.xcodeproj/xcshareddata/xcschemes/Knock.xcscheme +++ /dev/null @@ -1,79 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/README.md b/README.md index c86d7fa..8cda1c6 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,3 @@ - # Official Knock iOS SDK [![GitHub Release](https://img.shields.io/github/v/release/knocklabs/knock-swift?style=flat)](https://github.com/knocklabs/knock-swift/releases/latest) @@ -10,8 +9,6 @@ ![min ios version is 16](https://img.shields.io/badge/min%20iOS%20version-16-blue) [![GitHub license](https://img.shields.io/badge/license-MIT-lightgrey.svg?style=flat)](https://github.com/knocklabs/ios-example-app/blob/main/LICENSE) - - --- Knock is a flexible, reliable notifications infrastructure that's built to scale with you. Use our iOS SDK to engage users with in-app feeds, setup push notifications, and manage notification preferences. @@ -34,7 +31,7 @@ See the [iOS Example App](https://github.com/knocklabs/ios-example-app) for more ### Swift Package Manager -There are two ways to add this as a dependency using the Swift Package Manager: +There are two ways to add this as a dependency using the Swift Package Manager: 1. Using Xcode 2. Manually via `Package.swift` @@ -46,7 +43,7 @@ There are two ways to add this as a dependency using the Swift Package Manager: Screenshot 2023-06-27 at 19 41 32 2. Search for `https://github.com/knocklabs/knock-swift.git` and then click `Add Package` -*Note: We recommend that you set the Dependency Rule to Up to Next Major Version. While we encourage you to keep your app up to date with the latest SDK, major versions can include breaking changes or new features that require your attention.* + _Note: We recommend that you set the Dependency Rule to Up to Next Major Version. While we encourage you to keep your app up to date with the latest SDK, major versions can include breaking changes or new features that require your attention._ Screenshot 2023-06-27 at 19 42 09 @@ -54,9 +51,9 @@ There are two ways to add this as a dependency using the Swift Package Manager: If you are managing dependencies using the `Package.swift` file, just add this to you dependencies array: -``` swift +```swift dependencies: [ - .package(url: "https://github.com/knocklabs/knock-swift.git", .upToNextMajor(from: "1.2.5")) + .package(url: "https://github.com/knocklabs/knock-swift.git", .upToNextMajor(from: "1.2.6")) ] ``` @@ -69,7 +66,7 @@ platform :ios, '16.0' use_frameworks! target 'MyApp' do - pod 'Knock', '~> 1.2.5' + pod 'Knock', '~> 1.2.6' end ``` @@ -89,12 +86,12 @@ As a last option, you could manually copy the files inside the `Sources` folder You can now start using the SDK: -``` swift +```swift import Knock -/* - Setup the shared Knock instance as soon as you can. - Note: pushChannelId is required if you want to use our KnockAppDelegate helper. +/* + Setup the shared Knock instance as soon as you can. + Note: pushChannelId is required if you want to use our KnockAppDelegate helper. Otherwise, this field is optional. */ try? Knock.shared.setup(publishableKey: "your-pk", pushChannelId: "apns-push-channel-id") diff --git a/Sources/Knock.swift b/Sources/Knock.swift index 97df829..da27adc 100644 --- a/Sources/Knock.swift +++ b/Sources/Knock.swift @@ -10,7 +10,7 @@ import OSLog // Knock client SDK. public class Knock { - internal static let clientVersion = "1.2.5" + internal static let clientVersion = "1.2.6" public static var shared: Knock = Knock() diff --git a/Sources/Models/ChannelData.swift b/Sources/Models/ChannelData.swift index 1180b3f..e69b2ee 100644 --- a/Sources/Models/ChannelData.swift +++ b/Sources/Models/ChannelData.swift @@ -6,22 +6,27 @@ // import Foundation -import AnyCodable public extension Knock { struct ChannelData: Codable { public let channel_id: String - public let data: ChannelDataData? + public let data: [String: AnyCodable]? + + public init(channel_id: String, data: [String: AnyCodable]?) { + self.channel_id = channel_id + self.data = data + } } - struct ChannelDataData: Codable { - public let tokens: [String]? - public let devices: [Device]? - } - - struct Device: Codable { + struct Device: Codable, Equatable { public let token: String public let locale: String? public let timezone: String? + + public init(token: String, locale: String?, timezone: String?) { + self.token = token + self.locale = locale + self.timezone = timezone + } } } diff --git a/Sources/Modules/ChannelModule.swift b/Sources/Modules/ChannelModule.swift index e2eb5e2..5069b0f 100644 --- a/Sources/Modules/ChannelModule.swift +++ b/Sources/Modules/ChannelModule.swift @@ -158,7 +158,7 @@ internal class ChannelModule { return try await registerNewDevicesDataOnServer( devices: newDevices, channelId: channelId) } else { - return existingChannelData + return channelData } } catch let userIdError as Knock.KnockError where userIdError == Knock.KnockError.userIdNotSetError @@ -182,29 +182,29 @@ internal class ChannelModule { } } - private func buildDeviceObject(token: String) -> Knock.Device { - return [ - "token": token, - "locale": Locale.current.identifier, - "timezone": TimeZone.current.identifier, - ] + internal func buildDeviceObject(token: String) -> Knock.Device { + return Knock.Device( + token: token, + locale: Locale.current.identifier, + timezone: TimeZone.current.identifier + ) } - private func filterTokensOutFromDevices( + internal func filterTokensOutFromDevices( devices: [Knock.Device], targetTokens: [String] ) -> [Knock.Device] { var filteredDevices: [Knock.Device] = devices - filteredDevices.removeAll(where: { targetTokens.contains($0["token"] as? String ?? "") }) + filteredDevices.removeAll(where: { targetTokens.contains($0.token) }) return filteredDevices } - private func addTokenToDevices( + internal func addTokenToDevices( devices: [Knock.Device], newToken: String ) -> [Knock.Device] { var updatedDevices: [Knock.Device] = devices - if !updatedDevices.contains(where: { $0["token"] as? String == newToken }) { + if !updatedDevices.contains(where: { $0.token == newToken }) { updatedDevices.append(buildDeviceObject(token: newToken)) } return updatedDevices diff --git a/Tests/KnockTests/ChannelTests.swift b/Tests/KnockTests/ChannelTests.swift index 887588d..87aefad 100644 --- a/Tests/KnockTests/ChannelTests.swift +++ b/Tests/KnockTests/ChannelTests.swift @@ -21,23 +21,23 @@ final class ChannelTests: XCTestCase { func testFilterTokensOut_RemovesMatchingTokens() { let devices: [Knock.Device] = [ - ["token": "a", "locale": "en_US", "timezone": "UTC"], - ["token": "b", "locale": "en_US", "timezone": "UTC"], - ["token": "c", "locale": "en_US", "timezone": "UTC"], + Knock.Device(token: "a", locale: "en_US", timezone: "UTC"), + Knock.Device(token: "b", locale: "en_US", timezone: "UTC"), + Knock.Device(token: "c", locale: "en_US", timezone: "UTC"), ] let result = channelModule.filterTokensOutFromDevices( devices: devices, targetTokens: ["a", "b"]) XCTAssertEqual(result.count, 1) - XCTAssertEqual(result.first?["token"] as? String, "c") + XCTAssertEqual(result.first?.token, "c") } func testFilterTokensOut_LeavesUnmatchedTokens() { let devices: [Knock.Device] = [ - ["token": "x", "locale": "en_US", "timezone": "UTC"] + Knock.Device(token: "x", locale: "en_US", timezone: "UTC") ] let result = channelModule.filterTokensOutFromDevices(devices: devices, targetTokens: ["y"]) XCTAssertEqual(result.count, 1) - XCTAssertEqual(result.first?["token"] as? String, "x") + XCTAssertEqual(result.first?.token, "x") } func testFilterTokensOut_WithEmptyInput_ReturnsEmpty() { @@ -49,36 +49,36 @@ final class ChannelTests: XCTestCase { func testAddToken_AddsNewToken() { let devices: [Knock.Device] = [ - ["token": "a", "locale": "en_US", "timezone": "UTC"] + Knock.Device(token: "a", locale: "en_US", timezone: "UTC") ] let result = channelModule.addTokenToDevices(devices: devices, newToken: "b") XCTAssertEqual(result.count, 2) - let tokens = result.compactMap { $0["token"] as? String } + let tokens = result.map { $0.token } XCTAssertTrue(tokens.contains("b")) } func testAddToken_DoesNotAddDuplicateToken() { let devices: [Knock.Device] = [ - ["token": "a", "locale": "en_US", "timezone": "UTC"] + Knock.Device(token: "a", locale: "en_US", timezone: "UTC") ] let result = channelModule.addTokenToDevices(devices: devices, newToken: "a") XCTAssertEqual(result.count, 1) - XCTAssertEqual(result.first?["token"] as? String, "a") + XCTAssertEqual(result.first?.token, "a") } func testAddToken_PreservesExistingDevices() { let devices: [Knock.Device] = [ - ["token": "a", "locale": "en_US", "timezone": "UTC"] + Knock.Device(token: "a", locale: "en_US", timezone: "UTC") ] let result = channelModule.addTokenToDevices(devices: devices, newToken: "b") - let tokens = result.compactMap { $0["token"] as? String } + let tokens = result.map { $0.token } XCTAssertEqual(tokens.sorted(), ["a", "b"]) } func testBuildDeviceObject_HasExpectedFields() { let device = channelModule.buildDeviceObject(token: "abc123") - XCTAssertEqual(device["token"] as? String, "abc123") - XCTAssertNotNil(device["locale"]) - XCTAssertNotNil(device["timezone"]) + XCTAssertEqual(device.token, "abc123") + XCTAssertNotNil(device.locale) + XCTAssertNotNil(device.timezone) } } diff --git a/Tests/KnockTests/InAppFeedViewModelTests.swift b/Tests/KnockTests/InAppFeedViewModelTests.swift index 0424302..ad18986 100644 --- a/Tests/KnockTests/InAppFeedViewModelTests.swift +++ b/Tests/KnockTests/InAppFeedViewModelTests.swift @@ -122,7 +122,7 @@ final class InAppFeedViewModelTests: XCTestCase { let item4 = generateTestFeedItem(status: .read) viewModel.feed.entries = [item, item2, item3, item4] - viewModel.feedClientOptions.archived = .include + viewModel.feedClientOptions.archived = .exclude await viewModel.optimisticallyBulkUpdateStatus(updatedStatus: .archived) XCTAssertTrue(viewModel.feed.entries.count == 0) XCTAssertTrue(viewModel.feed.meta.unreadCount == 0)