Skip to content

Commit

Permalink
Xcode project with RevenueCatUI + Tests (#3960)
Browse files Browse the repository at this point in the history
### RevenueCatUI and its tests are now accessible in the files
navigator:

<img width="555" alt="image"
src="https://github.com/RevenueCat/purchases-ios/assets/109382862/a4067d0a-62e5-43b2-bf77-a8a7ee1dd16e">

### It add two new schemes:

<img width="384" alt="image"
src="https://github.com/RevenueCat/purchases-ios/assets/109382862/94b80848-5cc3-4abc-b132-345d79a6f143">

Use RevenueCatUIDev to build RevenueCatUI, and RevenueCatUITests to run
its tests.

### Linting works:

<img width="716" alt="image"
src="https://github.com/RevenueCat/purchases-ios/assets/109382862/aacfa0bf-84af-494e-a4b1-9434de69b4f8">

### Individual tests can be run from the UI:

<img width="999" alt="image"
src="https://github.com/RevenueCat/purchases-ios/assets/109382862/902c5167-d352-4e6d-a848-c5d6c0e988de">

## N.B.

- Tests must be run via the RevenueCatUITest scheme.
- Xcode sometimes has difficulties switching schemes. If you see the
errors below, **clean the build folder** and try again and it will work
<img width="822" alt="image"
src="https://github.com/RevenueCat/purchases-ios/assets/109382862/0ac8dd77-676c-46e4-bc76-f8edf86f5a79">
- Building with the RevenueCatUIDev scheme creates some warnings related
to switches. Adding in an `@unknown default:` resolves the warning but
causes an error in other configurations ("Default will never be
executed").
<img width="801" alt="image"
src="https://github.com/RevenueCat/purchases-ios/assets/109382862/dcba6e0c-5755-4e5a-b940-ca270242b6bb">
- Because the root Package file was not altered, this PR won't have any
affect on how our package works when integrated via SPM.

---------

Co-authored-by: Cesar de la Vega <[email protected]>
  • Loading branch information
jamesrb1 and vegaro authored Jun 18, 2024
1 parent 5331ce9 commit 1499538
Show file tree
Hide file tree
Showing 10 changed files with 1,673 additions and 9 deletions.
54 changes: 54 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/RevenueCatUITests.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1540"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
buildArchitectures = "Automatic">
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "RevenueCatUITests"
BuildableName = "RevenueCatUITests"
BlueprintName = "RevenueCatUITests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
1,473 changes: 1,470 additions & 3 deletions RevenueCat.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1540"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
buildArchitectures = "Automatic">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "887A5FB92C1D036200E1A461"
BuildableName = "RevenueCatUI.framework"
BlueprintName = "RevenueCatUI"
ReferencedContainer = "container:RevenueCat.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<TestPlans>
<TestPlanReference
reference = "container:RevenueCatUI/RevenueCatUIDev.xctestplan"
default = "YES">
</TestPlanReference>
</TestPlans>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "887A5FB92C1D036200E1A461"
BuildableName = "RevenueCatUI.framework"
BlueprintName = "RevenueCatUI"
ReferencedContainer = "container:RevenueCat.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
8 changes: 8 additions & 0 deletions RevenueCat.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
7 changes: 7 additions & 0 deletions RevenueCatUI/Data/Localization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ private extension SubscriptionPeriod.Unit {
case .week: return .weekOfMonth
case .month: return .month
case .year: return .year
@unknown default:
Logger.warning("Unknown SubscriptionPeriod.Unit")
return .year
}
}

Expand All @@ -253,6 +256,7 @@ private extension SubscriptionPeriod {
case .year:
return DateComponents(year: self.value)
@unknown default:
Logger.warning("Unknown SubscriptionPeriod")
return .init()
}
}
Expand All @@ -273,6 +277,9 @@ private extension PackageType {

case .unknown, .custom:
return nil
@unknown default:
Logger.warning("Unknown localizationKey")
return nil
}
}

Expand Down
8 changes: 8 additions & 0 deletions RevenueCatUI/Data/PaywallViewMode+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,39 @@ extension PaywallViewMode {
var displayAllPlansByDefault: Bool {
switch self {
case .fullScreen: return true
#if !os(watchOS)
case .footer: return true
case .condensedFooter: return false
#endif
}
}

var displayAllPlansButton: Bool {
switch self {
case .fullScreen: return false
#if !os(watchOS)
case .footer: return false
case .condensedFooter: return true
#endif
}
}

var shouldDisplayBackground: Bool {
switch self {
case .fullScreen: return true
#if !os(watchOS)
case .footer, .condensedFooter: return false
#endif
}
}

func shouldDisplayInlineOfferDetails(displayingAllPlans: Bool) -> Bool {
switch self {
case .fullScreen: return false
#if !os(watchOS)
case .footer: return false
case .condensedFooter: return !displayingAllPlans
#endif
}
}

Expand Down
2 changes: 1 addition & 1 deletion RevenueCatUI/Helpers/Bundle+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import Foundation

#if COCOAPODS
#if COCOAPODS || !SWIFT_PACKAGE

extension Bundle {

Expand Down
24 changes: 24 additions & 0 deletions RevenueCatUI/RevenueCatUIDev.xctestplan
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"configurations" : [
{
"id" : "F153BBC4-4E6D-4941-BBAF-962BE3A88B9C",
"name" : "Configuration 1",
"options" : {

}
}
],
"defaultOptions" : {

},
"testTargets" : [
{
"target" : {
"containerPath" : "container:RevenueCat.xcodeproj",
"identifier" : "887A63202C1D174200E1A461",
"name" : "RevenueCatUITestsDev"
}
}
],
"version" : 1
}
24 changes: 24 additions & 0 deletions RevenueCatUIDev/RevenueCatUIDev.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// Copyright RevenueCat Inc. All Rights Reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// RevenueCatUIDev.h
//
// Created by James Borthwick on 2024-06-14.

#import <Foundation/Foundation.h>

//! Project version number for RevenueCatUIDev.
FOUNDATION_EXPORT double RevenueCatUIDevVersionNumber;

//! Project version string for RevenueCatUIDev.
FOUNDATION_EXPORT const unsigned char RevenueCatUIDevVersionString[];

// In this header, you should import all the public headers of your framework using statements like #import <RevenueCatUIDev/PublicHeader.h>


Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ struct SamplePaywallsList: View {
self.list(with: Self.loader)
.navigationTitle("Example Paywalls")
}
.sheet(item: self.$display) { display in
self.view(for: display)
}
.navigationTitle("Paywalls")
.navigationViewStyle(StackNavigationViewStyle())
.sheet(item: self.$display) { display in
self.view(for: display)
}
.navigationTitle("Paywalls")
.navigationViewStyle(StackNavigationViewStyle())
}

@ViewBuilder
Expand Down

0 comments on commit 1499538

Please sign in to comment.