├── .gitignore
├── .swiftpm
└── xcode
│ └── package.xcworkspace
│ └── contents.xcworkspacedata
├── Configs
├── FeatureFlagsController.plist
└── FeatureFlagsControllerTests.plist
├── Example App
├── FeatureFlagsExample.xcodeproj
│ ├── project.pbxproj
│ └── project.xcworkspace
│ │ └── contents.xcworkspacedata
├── FeatureFlagsExample.xcworkspace
│ └── contents.xcworkspacedata
└── FeatureFlagsExample
│ ├── AppDelegate.swift
│ ├── Assets.xcassets
│ ├── AccentColor.colorset
│ │ └── Contents.json
│ ├── AppIcon.appiconset
│ │ └── Contents.json
│ └── Contents.json
│ ├── Base.lproj
│ └── LaunchScreen.storyboard
│ ├── Example1ViewController.swift
│ ├── Example2ViewController.swift
│ ├── Example3View.swift
│ ├── Info.plist
│ ├── RemoteFeatureFlag.swift
│ └── SceneDelegate.swift
├── FeatureFlagsController.podspec
├── FeatureFlagsController.xcodeproj
├── project.pbxproj
├── project.xcworkspace
│ └── contents.xcworkspacedata
└── xcshareddata
│ └── xcschemes
│ ├── FeatureFlagsController-iOS.xcscheme
│ ├── FeatureFlagsController-macOS.xcscheme
│ ├── FeatureFlagsController-tvOS.xcscheme
│ └── FeatureFlagsController-watchOS.xcscheme
├── LICENSE.md
├── Package.swift
├── README.md
├── Sources
└── FeatureFlagsController
│ ├── FeatureFlag.swift
│ ├── FeatureFlagType.swift
│ ├── FeatureFlagsController.swift
│ ├── Flag Types
│ ├── CountFeatureFlag.swift
│ ├── FeatureFlagsGroup.swift
│ ├── PickerFeatureFlag.swift
│ └── ToggleFeatureFlag.swift
│ └── UI
│ ├── FeatureFlagViewFactory.swift
│ └── FeatureFlagsView.swift
└── Tests
├── FeatureFlagsControllerTests
└── FeatureFlagsControllerTests.swift
└── LinuxMain.swift
/.gitignore:
--------------------------------------------------------------------------------
1 | # Xcode
2 | #
3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
4 |
5 | ## User settings
6 | xcuserdata/
7 |
8 | ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
9 | *.xcscmblueprint
10 | *.xccheckout
11 |
12 | ## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
13 | build/
14 | DerivedData/
15 | *.moved-aside
16 | *.pbxuser
17 | !default.pbxuser
18 | *.mode1v3
19 | !default.mode1v3
20 | *.mode2v3
21 | !default.mode2v3
22 | *.perspectivev3
23 | !default.perspectivev3
24 |
25 | ## Obj-C/Swift specific
26 | *.hmap
27 |
28 | ## App packaging
29 | *.ipa
30 | *.dSYM.zip
31 | *.dSYM
32 |
33 | ## Playgrounds
34 | timeline.xctimeline
35 | playground.xcworkspace
36 |
37 | # Swift Package Manager
38 | #
39 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
40 | # Packages/
41 | # Package.pins
42 | # Package.resolved
43 | # *.xcodeproj
44 | #
45 | # Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata
46 | # hence it is not needed unless you have added a package configuration file to your project
47 | # .swiftpm
48 |
49 | .build/
50 |
51 | # CocoaPods
52 | #
53 | # We recommend against adding the Pods directory to your .gitignore. However
54 | # you should judge for yourself, the pros and cons are mentioned at:
55 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
56 | #
57 | # Pods/
58 | #
59 | # Add this line if you want to avoid checking in source code from the Xcode workspace
60 | # *.xcworkspace
61 |
62 | # Carthage
63 | #
64 | # Add this line if you want to avoid checking in source code from Carthage dependencies.
65 | # Carthage/Checkouts
66 |
67 | Carthage/Build/
68 |
69 | # Accio dependency management
70 | Dependencies/
71 | .accio/
72 |
73 | # fastlane
74 | #
75 | # It is recommended to not store the screenshots in the git repo.
76 | # Instead, use fastlane to re-generate the screenshots whenever they are needed.
77 | # For more information about the recommended setup visit:
78 | # https://docs.fastlane.tools/best-practices/source-control/#source-control
79 |
80 | fastlane/report.xml
81 | fastlane/Preview.html
82 | fastlane/screenshots/**/*.png
83 | fastlane/test_output
84 |
85 | # Code Injection
86 | #
87 | # After new code Injection tools there's a generated folder /iOSInjectionProject
88 | # https://github.com/johnno1962/injectionforxcode
89 |
90 | iOSInjectionProject/
91 |
--------------------------------------------------------------------------------
/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Configs/FeatureFlagsController.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | FMWK
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | $(CURRENT_PROJECT_VERSION)
23 | NSHumanReadableCopyright
24 | Copyright © 2020 Jérôme Alves. All rights reserved.
25 | NSPrincipalClass
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/Configs/FeatureFlagsControllerTests.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 |
24 |
25 |
--------------------------------------------------------------------------------
/Example App/FeatureFlagsExample.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 50;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 753760502822DE3800C373E6 /* Example3View.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7537604F2822DE3800C373E6 /* Example3View.swift */; };
11 | 7561A4F92518979100F405DA /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7561A4F82518979100F405DA /* AppDelegate.swift */; };
12 | 7561A4FB2518979100F405DA /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7561A4FA2518979100F405DA /* SceneDelegate.swift */; };
13 | 7561A5022518979200F405DA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7561A5012518979200F405DA /* Assets.xcassets */; };
14 | 7561A5052518979200F405DA /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7561A5032518979200F405DA /* LaunchScreen.storyboard */; };
15 | 7561A558251898C900F405DA /* Example1ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7561A556251898C900F405DA /* Example1ViewController.swift */; };
16 | 7561A559251898C900F405DA /* Example2ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7561A557251898C900F405DA /* Example2ViewController.swift */; };
17 | 7561A5772518992700F405DA /* RemoteFeatureFlag.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7561A5762518992700F405DA /* RemoteFeatureFlag.swift */; };
18 | 7561A57C25189ADE00F405DA /* FeatureFlagsController.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7561A5432518984E00F405DA /* FeatureFlagsController.framework */; };
19 | 7561A57D25189ADE00F405DA /* FeatureFlagsController.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 7561A5432518984E00F405DA /* FeatureFlagsController.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
20 | /* End PBXBuildFile section */
21 |
22 | /* Begin PBXContainerItemProxy section */
23 | 7561A5422518984E00F405DA /* PBXContainerItemProxy */ = {
24 | isa = PBXContainerItemProxy;
25 | containerPortal = 7561A5382518984E00F405DA /* FeatureFlagsController.xcodeproj */;
26 | proxyType = 2;
27 | remoteGlobalIDString = 52D6D97C1BEFF229002C0205;
28 | remoteInfo = "FeatureFlagsController-iOS";
29 | };
30 | 7561A54A2518984E00F405DA /* PBXContainerItemProxy */ = {
31 | isa = PBXContainerItemProxy;
32 | containerPortal = 7561A5382518984E00F405DA /* FeatureFlagsController.xcodeproj */;
33 | proxyType = 2;
34 | remoteGlobalIDString = 52D6D9861BEFF229002C0205;
35 | remoteInfo = "FeatureFlagsController-iOS Tests";
36 | };
37 | 7561A5532518986C00F405DA /* PBXContainerItemProxy */ = {
38 | isa = PBXContainerItemProxy;
39 | containerPortal = 7561A5382518984E00F405DA /* FeatureFlagsController.xcodeproj */;
40 | proxyType = 1;
41 | remoteGlobalIDString = 52D6D97B1BEFF229002C0205;
42 | remoteInfo = "FeatureFlagsController-iOS";
43 | };
44 | /* End PBXContainerItemProxy section */
45 |
46 | /* Begin PBXCopyFilesBuildPhase section */
47 | 7561A57E25189ADE00F405DA /* Embed Frameworks */ = {
48 | isa = PBXCopyFilesBuildPhase;
49 | buildActionMask = 2147483647;
50 | dstPath = "";
51 | dstSubfolderSpec = 10;
52 | files = (
53 | 7561A57D25189ADE00F405DA /* FeatureFlagsController.framework in Embed Frameworks */,
54 | );
55 | name = "Embed Frameworks";
56 | runOnlyForDeploymentPostprocessing = 0;
57 | };
58 | /* End PBXCopyFilesBuildPhase section */
59 |
60 | /* Begin PBXFileReference section */
61 | 7537604F2822DE3800C373E6 /* Example3View.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Example3View.swift; sourceTree = ""; };
62 | 7561A4F52518979100F405DA /* FeatureFlagsExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FeatureFlagsExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
63 | 7561A4F82518979100F405DA /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; };
64 | 7561A4FA2518979100F405DA /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; };
65 | 7561A5012518979200F405DA /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; };
66 | 7561A5042518979200F405DA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; };
67 | 7561A5062518979200F405DA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
68 | 7561A5382518984E00F405DA /* FeatureFlagsController.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = FeatureFlagsController.xcodeproj; path = ../FeatureFlagsController.xcodeproj; sourceTree = ""; };
69 | 7561A556251898C900F405DA /* Example1ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Example1ViewController.swift; sourceTree = ""; };
70 | 7561A557251898C900F405DA /* Example2ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Example2ViewController.swift; sourceTree = ""; };
71 | 7561A5762518992700F405DA /* RemoteFeatureFlag.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RemoteFeatureFlag.swift; sourceTree = ""; };
72 | /* End PBXFileReference section */
73 |
74 | /* Begin PBXFrameworksBuildPhase section */
75 | 7561A4F22518979100F405DA /* Frameworks */ = {
76 | isa = PBXFrameworksBuildPhase;
77 | buildActionMask = 2147483647;
78 | files = (
79 | 7561A57C25189ADE00F405DA /* FeatureFlagsController.framework in Frameworks */,
80 | );
81 | runOnlyForDeploymentPostprocessing = 0;
82 | };
83 | /* End PBXFrameworksBuildPhase section */
84 |
85 | /* Begin PBXGroup section */
86 | 7561A4EC2518979100F405DA = {
87 | isa = PBXGroup;
88 | children = (
89 | 7561A4F72518979100F405DA /* FeatureFlagsExample */,
90 | 7561A4F62518979100F405DA /* Products */,
91 | 7561A57B25189ADE00F405DA /* Frameworks */,
92 | 7561A5382518984E00F405DA /* FeatureFlagsController.xcodeproj */,
93 | );
94 | sourceTree = "";
95 | };
96 | 7561A4F62518979100F405DA /* Products */ = {
97 | isa = PBXGroup;
98 | children = (
99 | 7561A4F52518979100F405DA /* FeatureFlagsExample.app */,
100 | );
101 | name = Products;
102 | sourceTree = "";
103 | };
104 | 7561A4F72518979100F405DA /* FeatureFlagsExample */ = {
105 | isa = PBXGroup;
106 | children = (
107 | 7561A4F82518979100F405DA /* AppDelegate.swift */,
108 | 7561A4FA2518979100F405DA /* SceneDelegate.swift */,
109 | 7561A556251898C900F405DA /* Example1ViewController.swift */,
110 | 7561A557251898C900F405DA /* Example2ViewController.swift */,
111 | 7537604F2822DE3800C373E6 /* Example3View.swift */,
112 | 7561A5762518992700F405DA /* RemoteFeatureFlag.swift */,
113 | 7561A5012518979200F405DA /* Assets.xcassets */,
114 | 7561A5032518979200F405DA /* LaunchScreen.storyboard */,
115 | 7561A5062518979200F405DA /* Info.plist */,
116 | );
117 | path = FeatureFlagsExample;
118 | sourceTree = "";
119 | };
120 | 7561A5392518984E00F405DA /* Products */ = {
121 | isa = PBXGroup;
122 | children = (
123 | 7561A5432518984E00F405DA /* FeatureFlagsController.framework */,
124 | 7561A54B2518984E00F405DA /* FeatureFlagsController-iOS Tests.xctest */,
125 | );
126 | name = Products;
127 | sourceTree = "";
128 | };
129 | 7561A57B25189ADE00F405DA /* Frameworks */ = {
130 | isa = PBXGroup;
131 | children = (
132 | );
133 | name = Frameworks;
134 | sourceTree = "";
135 | };
136 | /* End PBXGroup section */
137 |
138 | /* Begin PBXNativeTarget section */
139 | 7561A4F42518979100F405DA /* FeatureFlagsExample */ = {
140 | isa = PBXNativeTarget;
141 | buildConfigurationList = 7561A5092518979200F405DA /* Build configuration list for PBXNativeTarget "FeatureFlagsExample" */;
142 | buildPhases = (
143 | 7561A4F12518979100F405DA /* Sources */,
144 | 7561A4F22518979100F405DA /* Frameworks */,
145 | 7561A4F32518979100F405DA /* Resources */,
146 | 7561A57E25189ADE00F405DA /* Embed Frameworks */,
147 | );
148 | buildRules = (
149 | );
150 | dependencies = (
151 | 7561A5542518986C00F405DA /* PBXTargetDependency */,
152 | );
153 | name = FeatureFlagsExample;
154 | productName = FeatureFlagsExample;
155 | productReference = 7561A4F52518979100F405DA /* FeatureFlagsExample.app */;
156 | productType = "com.apple.product-type.application";
157 | };
158 | /* End PBXNativeTarget section */
159 |
160 | /* Begin PBXProject section */
161 | 7561A4ED2518979100F405DA /* Project object */ = {
162 | isa = PBXProject;
163 | attributes = {
164 | LastSwiftUpdateCheck = 1200;
165 | LastUpgradeCheck = 1200;
166 | TargetAttributes = {
167 | 7561A4F42518979100F405DA = {
168 | CreatedOnToolsVersion = 12.0;
169 | };
170 | };
171 | };
172 | buildConfigurationList = 7561A4F02518979100F405DA /* Build configuration list for PBXProject "FeatureFlagsExample" */;
173 | compatibilityVersion = "Xcode 9.3";
174 | developmentRegion = en;
175 | hasScannedForEncodings = 0;
176 | knownRegions = (
177 | en,
178 | Base,
179 | );
180 | mainGroup = 7561A4EC2518979100F405DA;
181 | productRefGroup = 7561A4F62518979100F405DA /* Products */;
182 | projectDirPath = "";
183 | projectReferences = (
184 | {
185 | ProductGroup = 7561A5392518984E00F405DA /* Products */;
186 | ProjectRef = 7561A5382518984E00F405DA /* FeatureFlagsController.xcodeproj */;
187 | },
188 | );
189 | projectRoot = "";
190 | targets = (
191 | 7561A4F42518979100F405DA /* FeatureFlagsExample */,
192 | );
193 | };
194 | /* End PBXProject section */
195 |
196 | /* Begin PBXReferenceProxy section */
197 | 7561A5432518984E00F405DA /* FeatureFlagsController.framework */ = {
198 | isa = PBXReferenceProxy;
199 | fileType = wrapper.framework;
200 | path = FeatureFlagsController.framework;
201 | remoteRef = 7561A5422518984E00F405DA /* PBXContainerItemProxy */;
202 | sourceTree = BUILT_PRODUCTS_DIR;
203 | };
204 | 7561A54B2518984E00F405DA /* FeatureFlagsController-iOS Tests.xctest */ = {
205 | isa = PBXReferenceProxy;
206 | fileType = wrapper.cfbundle;
207 | path = "FeatureFlagsController-iOS Tests.xctest";
208 | remoteRef = 7561A54A2518984E00F405DA /* PBXContainerItemProxy */;
209 | sourceTree = BUILT_PRODUCTS_DIR;
210 | };
211 | /* End PBXReferenceProxy section */
212 |
213 | /* Begin PBXResourcesBuildPhase section */
214 | 7561A4F32518979100F405DA /* Resources */ = {
215 | isa = PBXResourcesBuildPhase;
216 | buildActionMask = 2147483647;
217 | files = (
218 | 7561A5052518979200F405DA /* LaunchScreen.storyboard in Resources */,
219 | 7561A5022518979200F405DA /* Assets.xcassets in Resources */,
220 | );
221 | runOnlyForDeploymentPostprocessing = 0;
222 | };
223 | /* End PBXResourcesBuildPhase section */
224 |
225 | /* Begin PBXSourcesBuildPhase section */
226 | 7561A4F12518979100F405DA /* Sources */ = {
227 | isa = PBXSourcesBuildPhase;
228 | buildActionMask = 2147483647;
229 | files = (
230 | 7561A4F92518979100F405DA /* AppDelegate.swift in Sources */,
231 | 753760502822DE3800C373E6 /* Example3View.swift in Sources */,
232 | 7561A5772518992700F405DA /* RemoteFeatureFlag.swift in Sources */,
233 | 7561A559251898C900F405DA /* Example2ViewController.swift in Sources */,
234 | 7561A4FB2518979100F405DA /* SceneDelegate.swift in Sources */,
235 | 7561A558251898C900F405DA /* Example1ViewController.swift in Sources */,
236 | );
237 | runOnlyForDeploymentPostprocessing = 0;
238 | };
239 | /* End PBXSourcesBuildPhase section */
240 |
241 | /* Begin PBXTargetDependency section */
242 | 7561A5542518986C00F405DA /* PBXTargetDependency */ = {
243 | isa = PBXTargetDependency;
244 | name = "FeatureFlagsController-iOS";
245 | targetProxy = 7561A5532518986C00F405DA /* PBXContainerItemProxy */;
246 | };
247 | /* End PBXTargetDependency section */
248 |
249 | /* Begin PBXVariantGroup section */
250 | 7561A5032518979200F405DA /* LaunchScreen.storyboard */ = {
251 | isa = PBXVariantGroup;
252 | children = (
253 | 7561A5042518979200F405DA /* Base */,
254 | );
255 | name = LaunchScreen.storyboard;
256 | sourceTree = "";
257 | };
258 | /* End PBXVariantGroup section */
259 |
260 | /* Begin XCBuildConfiguration section */
261 | 7561A5072518979200F405DA /* Debug */ = {
262 | isa = XCBuildConfiguration;
263 | buildSettings = {
264 | ALWAYS_SEARCH_USER_PATHS = NO;
265 | CLANG_ANALYZER_NONNULL = YES;
266 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
267 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
268 | CLANG_CXX_LIBRARY = "libc++";
269 | CLANG_ENABLE_MODULES = YES;
270 | CLANG_ENABLE_OBJC_ARC = YES;
271 | CLANG_ENABLE_OBJC_WEAK = YES;
272 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
273 | CLANG_WARN_BOOL_CONVERSION = YES;
274 | CLANG_WARN_COMMA = YES;
275 | CLANG_WARN_CONSTANT_CONVERSION = YES;
276 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
277 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
278 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
279 | CLANG_WARN_EMPTY_BODY = YES;
280 | CLANG_WARN_ENUM_CONVERSION = YES;
281 | CLANG_WARN_INFINITE_RECURSION = YES;
282 | CLANG_WARN_INT_CONVERSION = YES;
283 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
284 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
285 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
286 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
287 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
288 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
289 | CLANG_WARN_STRICT_PROTOTYPES = YES;
290 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
291 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
292 | CLANG_WARN_UNREACHABLE_CODE = YES;
293 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
294 | COPY_PHASE_STRIP = NO;
295 | DEBUG_INFORMATION_FORMAT = dwarf;
296 | ENABLE_STRICT_OBJC_MSGSEND = YES;
297 | ENABLE_TESTABILITY = YES;
298 | GCC_C_LANGUAGE_STANDARD = gnu11;
299 | GCC_DYNAMIC_NO_PIC = NO;
300 | GCC_NO_COMMON_BLOCKS = YES;
301 | GCC_OPTIMIZATION_LEVEL = 0;
302 | GCC_PREPROCESSOR_DEFINITIONS = (
303 | "DEBUG=1",
304 | "$(inherited)",
305 | );
306 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
307 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
308 | GCC_WARN_UNDECLARED_SELECTOR = YES;
309 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
310 | GCC_WARN_UNUSED_FUNCTION = YES;
311 | GCC_WARN_UNUSED_VARIABLE = YES;
312 | IPHONEOS_DEPLOYMENT_TARGET = 14.0;
313 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
314 | MTL_FAST_MATH = YES;
315 | ONLY_ACTIVE_ARCH = YES;
316 | SDKROOT = iphoneos;
317 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
318 | SWIFT_OPTIMIZATION_LEVEL = "-Onone";
319 | };
320 | name = Debug;
321 | };
322 | 7561A5082518979200F405DA /* Release */ = {
323 | isa = XCBuildConfiguration;
324 | buildSettings = {
325 | ALWAYS_SEARCH_USER_PATHS = NO;
326 | CLANG_ANALYZER_NONNULL = YES;
327 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
328 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
329 | CLANG_CXX_LIBRARY = "libc++";
330 | CLANG_ENABLE_MODULES = YES;
331 | CLANG_ENABLE_OBJC_ARC = YES;
332 | CLANG_ENABLE_OBJC_WEAK = YES;
333 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
334 | CLANG_WARN_BOOL_CONVERSION = YES;
335 | CLANG_WARN_COMMA = YES;
336 | CLANG_WARN_CONSTANT_CONVERSION = YES;
337 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
338 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
339 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
340 | CLANG_WARN_EMPTY_BODY = YES;
341 | CLANG_WARN_ENUM_CONVERSION = YES;
342 | CLANG_WARN_INFINITE_RECURSION = YES;
343 | CLANG_WARN_INT_CONVERSION = YES;
344 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
345 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
346 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
347 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
348 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
349 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
350 | CLANG_WARN_STRICT_PROTOTYPES = YES;
351 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
352 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
353 | CLANG_WARN_UNREACHABLE_CODE = YES;
354 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
355 | COPY_PHASE_STRIP = NO;
356 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
357 | ENABLE_NS_ASSERTIONS = NO;
358 | ENABLE_STRICT_OBJC_MSGSEND = YES;
359 | GCC_C_LANGUAGE_STANDARD = gnu11;
360 | GCC_NO_COMMON_BLOCKS = YES;
361 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
362 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
363 | GCC_WARN_UNDECLARED_SELECTOR = YES;
364 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
365 | GCC_WARN_UNUSED_FUNCTION = YES;
366 | GCC_WARN_UNUSED_VARIABLE = YES;
367 | IPHONEOS_DEPLOYMENT_TARGET = 14.0;
368 | MTL_ENABLE_DEBUG_INFO = NO;
369 | MTL_FAST_MATH = YES;
370 | SDKROOT = iphoneos;
371 | SWIFT_COMPILATION_MODE = wholemodule;
372 | SWIFT_OPTIMIZATION_LEVEL = "-O";
373 | VALIDATE_PRODUCT = YES;
374 | };
375 | name = Release;
376 | };
377 | 7561A50A2518979200F405DA /* Debug */ = {
378 | isa = XCBuildConfiguration;
379 | buildSettings = {
380 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
381 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
382 | CODE_SIGN_STYLE = Automatic;
383 | DEVELOPMENT_TEAM = JKFCB4CN7C;
384 | INFOPLIST_FILE = FeatureFlagsExample/Info.plist;
385 | IPHONEOS_DEPLOYMENT_TARGET = 13.0;
386 | LD_RUNPATH_SEARCH_PATHS = (
387 | "$(inherited)",
388 | "@executable_path/Frameworks",
389 | );
390 | PRODUCT_BUNDLE_IDENTIFIER = com.datadog.FeatureFlagsExample;
391 | PRODUCT_NAME = "$(TARGET_NAME)";
392 | SWIFT_VERSION = 5.0;
393 | TARGETED_DEVICE_FAMILY = "1,2";
394 | };
395 | name = Debug;
396 | };
397 | 7561A50B2518979200F405DA /* Release */ = {
398 | isa = XCBuildConfiguration;
399 | buildSettings = {
400 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
401 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
402 | CODE_SIGN_STYLE = Automatic;
403 | DEVELOPMENT_TEAM = JKFCB4CN7C;
404 | INFOPLIST_FILE = FeatureFlagsExample/Info.plist;
405 | IPHONEOS_DEPLOYMENT_TARGET = 13.0;
406 | LD_RUNPATH_SEARCH_PATHS = (
407 | "$(inherited)",
408 | "@executable_path/Frameworks",
409 | );
410 | PRODUCT_BUNDLE_IDENTIFIER = com.datadog.FeatureFlagsExample;
411 | PRODUCT_NAME = "$(TARGET_NAME)";
412 | SWIFT_VERSION = 5.0;
413 | TARGETED_DEVICE_FAMILY = "1,2";
414 | };
415 | name = Release;
416 | };
417 | /* End XCBuildConfiguration section */
418 |
419 | /* Begin XCConfigurationList section */
420 | 7561A4F02518979100F405DA /* Build configuration list for PBXProject "FeatureFlagsExample" */ = {
421 | isa = XCConfigurationList;
422 | buildConfigurations = (
423 | 7561A5072518979200F405DA /* Debug */,
424 | 7561A5082518979200F405DA /* Release */,
425 | );
426 | defaultConfigurationIsVisible = 0;
427 | defaultConfigurationName = Release;
428 | };
429 | 7561A5092518979200F405DA /* Build configuration list for PBXNativeTarget "FeatureFlagsExample" */ = {
430 | isa = XCConfigurationList;
431 | buildConfigurations = (
432 | 7561A50A2518979200F405DA /* Debug */,
433 | 7561A50B2518979200F405DA /* Release */,
434 | );
435 | defaultConfigurationIsVisible = 0;
436 | defaultConfigurationName = Release;
437 | };
438 | /* End XCConfigurationList section */
439 | };
440 | rootObject = 7561A4ED2518979100F405DA /* Project object */;
441 | }
442 |
--------------------------------------------------------------------------------
/Example App/FeatureFlagsExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Example App/FeatureFlagsExample.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
9 |
10 |
12 |
13 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/Example App/FeatureFlagsExample/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | /*
2 | * Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
3 | * This product includes software developed at Datadog (https://www.datadoghq.com/).
4 | * Copyright 2020 Datadog, Inc.
5 | */
6 |
7 | import UIKit
8 |
9 | @main
10 | class AppDelegate: UIResponder, UIApplicationDelegate {
11 |
12 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
13 | return true
14 | }
15 |
16 | func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
17 | return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/Example App/FeatureFlagsExample/Assets.xcassets/AccentColor.colorset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "colors" : [
3 | {
4 | "idiom" : "universal"
5 | }
6 | ],
7 | "info" : {
8 | "author" : "xcode",
9 | "version" : 1
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/Example App/FeatureFlagsExample/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "scale" : "2x",
6 | "size" : "20x20"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "scale" : "3x",
11 | "size" : "20x20"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "scale" : "2x",
16 | "size" : "29x29"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "scale" : "3x",
21 | "size" : "29x29"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "scale" : "2x",
26 | "size" : "40x40"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "scale" : "3x",
31 | "size" : "40x40"
32 | },
33 | {
34 | "idiom" : "iphone",
35 | "scale" : "2x",
36 | "size" : "60x60"
37 | },
38 | {
39 | "idiom" : "iphone",
40 | "scale" : "3x",
41 | "size" : "60x60"
42 | },
43 | {
44 | "idiom" : "ipad",
45 | "scale" : "1x",
46 | "size" : "20x20"
47 | },
48 | {
49 | "idiom" : "ipad",
50 | "scale" : "2x",
51 | "size" : "20x20"
52 | },
53 | {
54 | "idiom" : "ipad",
55 | "scale" : "1x",
56 | "size" : "29x29"
57 | },
58 | {
59 | "idiom" : "ipad",
60 | "scale" : "2x",
61 | "size" : "29x29"
62 | },
63 | {
64 | "idiom" : "ipad",
65 | "scale" : "1x",
66 | "size" : "40x40"
67 | },
68 | {
69 | "idiom" : "ipad",
70 | "scale" : "2x",
71 | "size" : "40x40"
72 | },
73 | {
74 | "idiom" : "ipad",
75 | "scale" : "1x",
76 | "size" : "76x76"
77 | },
78 | {
79 | "idiom" : "ipad",
80 | "scale" : "2x",
81 | "size" : "76x76"
82 | },
83 | {
84 | "idiom" : "ipad",
85 | "scale" : "2x",
86 | "size" : "83.5x83.5"
87 | },
88 | {
89 | "idiom" : "ios-marketing",
90 | "scale" : "1x",
91 | "size" : "1024x1024"
92 | }
93 | ],
94 | "info" : {
95 | "author" : "xcode",
96 | "version" : 1
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/Example App/FeatureFlagsExample/Assets.xcassets/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "info" : {
3 | "author" : "xcode",
4 | "version" : 1
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/Example App/FeatureFlagsExample/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/Example App/FeatureFlagsExample/Example1ViewController.swift:
--------------------------------------------------------------------------------
1 | /*
2 | * Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
3 | * This product includes software developed at Datadog (https://www.datadoghq.com/).
4 | * Copyright 2020 Datadog, Inc.
5 | */
6 |
7 | import UIKit
8 | import Combine
9 | import FeatureFlagsController
10 |
11 | final class Example1ViewController: UIViewController {
12 |
13 | override var title: String? {
14 | get { "Example 1" }
15 | set {}
16 | }
17 |
18 | override func viewDidLoad() {
19 | view.backgroundColor = .systemBackground
20 |
21 | setUpSquareView()
22 | setUpExample2Button()
23 |
24 | setUpColorFeatureFlag()
25 | setUpRoundedCornersFeatureFlag()
26 | }
27 |
28 | // MARK: - Views
29 |
30 | private let squareView = UIView()
31 | private func setUpSquareView() {
32 | view.addSubview(squareView)
33 | squareView.translatesAutoresizingMaskIntoConstraints = false
34 | NSLayoutConstraint.activate([
35 | squareView.centerXAnchor.constraint(equalTo: view.centerXAnchor),
36 | squareView.centerYAnchor.constraint(equalTo: view.centerYAnchor),
37 | squareView.widthAnchor.constraint(equalToConstant: 150),
38 | squareView.heightAnchor.constraint(equalToConstant: 150),
39 | ])
40 | }
41 |
42 | private func setUpExample2Button() {
43 | let button = UIButton(type: .system)
44 | button.setTitle("Example 2", for: .normal)
45 | button.addTarget(self, action: #selector(openExample2), for: .touchUpInside)
46 | view.addSubview(button)
47 | button.translatesAutoresizingMaskIntoConstraints = false
48 | NSLayoutConstraint.activate([
49 | button.centerXAnchor.constraint(equalTo: view.centerXAnchor),
50 | button.bottomAnchor.constraint(equalTo: view.layoutMarginsGuide.bottomAnchor, constant: -16),
51 | ])
52 | }
53 |
54 | // MARK: - Feature Flags
55 |
56 | private var cancellables = Set()
57 |
58 | private enum Colors: String, CaseIterable {
59 | case red, green, blue
60 | }
61 |
62 | private func setUpColorFeatureFlag() {
63 | PickerFeatureFlag(
64 | title: "Color", defaultValue: Colors.red, group: "UIKIT EXAMPLE #1"
65 | )
66 | .register()
67 | .map {
68 | switch $0 {
69 | case .red: return UIColor.systemRed
70 | case .green: return UIColor.systemGreen
71 | case .blue: return UIColor.systemBlue
72 | }
73 | }
74 | .assign(to: \.backgroundColor, on: squareView)
75 | .store(in: &cancellables)
76 | }
77 |
78 | private func setUpRoundedCornersFeatureFlag() {
79 | FeatureFlagsGroup(
80 | title: "Rounded Corners",
81 | first: RemoteToggleFeatureFlag(
82 | key: "uses_rounded_corners"
83 | ),
84 | second: ToggleFeatureFlag(
85 | title: "Rounded Corners", defaultValue: true
86 | ),
87 | group: "UIKIT EXAMPLE #1"
88 | )
89 | .register()
90 | .map { $0 ? 16 : 0 }
91 | .assign(to: \.cornerRadius, on: squareView.layer)
92 | .store(in: &cancellables)
93 | }
94 |
95 | // MARK: - Actions
96 |
97 | @objc
98 | private func openExample2() {
99 | navigationController?.pushViewController(Example2ViewController(), animated: true)
100 | }
101 |
102 | }
103 |
--------------------------------------------------------------------------------
/Example App/FeatureFlagsExample/Example2ViewController.swift:
--------------------------------------------------------------------------------
1 | /*
2 | * Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
3 | * This product includes software developed at Datadog (https://www.datadoghq.com/).
4 | * Copyright 2020 Datadog, Inc.
5 | */
6 |
7 | import UIKit
8 | import Combine
9 | import SwiftUI
10 | import FeatureFlagsController
11 |
12 | final class Example2ViewController: UIViewController {
13 |
14 | override var title: String? {
15 | get { "Example 2" }
16 | set {}
17 | }
18 |
19 | override func viewDidLoad() {
20 | view.backgroundColor = .systemBackground
21 |
22 | setUpSquareView()
23 | setUpExample1Button()
24 |
25 | setUpOrientationFeatureFlag()
26 | }
27 |
28 | // MARK: - Views
29 |
30 | private let squareView = UIView()
31 |
32 | private func setUpSquareView() {
33 | view.addSubview(squareView)
34 | squareView.backgroundColor = .systemTeal
35 | squareView.translatesAutoresizingMaskIntoConstraints = false
36 | NSLayoutConstraint.activate([
37 | squareView.centerXAnchor.constraint(equalTo: view.centerXAnchor),
38 | squareView.centerYAnchor.constraint(equalTo: view.centerYAnchor),
39 | ])
40 | }
41 |
42 | private func setUpExample1Button() {
43 | let button = UIButton(type: .system)
44 | button.setTitle("Example 1", for: .normal)
45 | button.addTarget(self, action: #selector(openExample1), for: .touchUpInside)
46 | view.addSubview(button)
47 | button.translatesAutoresizingMaskIntoConstraints = false
48 | NSLayoutConstraint.activate([
49 | button.centerXAnchor.constraint(equalTo: view.centerXAnchor),
50 | button.bottomAnchor.constraint(equalTo: view.layoutMarginsGuide.bottomAnchor, constant: -16),
51 | ])
52 | }
53 |
54 | private lazy var portraitConstraints = [
55 | squareView.widthAnchor.constraint(equalToConstant: 150),
56 | squareView.heightAnchor.constraint(equalToConstant: 250),
57 | ]
58 |
59 | private lazy var landscapeConstraints = [
60 | squareView.widthAnchor.constraint(equalToConstant: 250),
61 | squareView.heightAnchor.constraint(equalToConstant: 150),
62 | ]
63 |
64 | // MARK: - Feature Flags
65 |
66 | private enum Orientation: String, CaseIterable {
67 | case portrait, landscape
68 | }
69 |
70 | private var cancellables = Set()
71 |
72 | private lazy var orientationFeatureFlag = PickerFeatureFlag(
73 | title: "Orientation",
74 | defaultValue: Orientation.portrait,
75 | group: "UIKIT EXAMPLE #2",
76 | style: SegmentedPickerStyle()
77 | )
78 |
79 | private func setUpOrientationFeatureFlag() {
80 | orientationFeatureFlag
81 | .register()
82 | .sink(receiveValue: { [unowned self] orientation in
83 | switch orientation {
84 | case .portrait:
85 | NSLayoutConstraint.deactivate(self.landscapeConstraints)
86 | NSLayoutConstraint.activate(self.portraitConstraints)
87 | case .landscape:
88 | NSLayoutConstraint.deactivate(self.portraitConstraints)
89 | NSLayoutConstraint.activate(self.landscapeConstraints)
90 | }
91 | })
92 | .store(in: &cancellables)
93 | }
94 |
95 | // MARK: - Actions
96 | @objc
97 | private func openExample1() {
98 | navigationController?.pushViewController(Example1ViewController(), animated: true)
99 | }
100 |
101 | }
102 |
--------------------------------------------------------------------------------
/Example App/FeatureFlagsExample/Example3View.swift:
--------------------------------------------------------------------------------
1 | /*
2 | * Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
3 | * This product includes software developed at Datadog (https://www.datadoghq.com/).
4 | * Copyright 2020 Datadog, Inc.
5 | */
6 |
7 | import SwiftUI
8 | import FeatureFlagsController
9 |
10 | @available(iOS 14, *)
11 | struct Example3View: View {
12 |
13 | static let trailingIndexFeatureFlag = ToggleFeatureFlag(
14 | title: "Trailing Index", defaultValue: true, group: "SWIFTUI EXAMPLE"
15 | )
16 |
17 | @FeatureFlag(trailingIndexFeatureFlag) // Either pass an existing, shared, feature flag...
18 | var trailingIndex
19 |
20 | @FeatureFlag(title: "Elements Count", range: 3...10, group: "SWIFTUI EXAMPLE") // ...or declare a new feature flag just for this view
21 | var elementsCount = 5
22 |
23 | var body: some View {
24 | List {
25 | ForEach(Array(1 ... elementsCount), id: \.self) { i in
26 | if trailingIndex {
27 | HStack {
28 | Text("Element")
29 | Spacer()
30 | Text("#\(i)").foregroundColor(.secondary)
31 | }
32 | } else {
33 | Text("Element #\(i)")
34 | }
35 | }
36 | }
37 | .navigationTitle($elementsCount.title + " \(elementsCount)/\($elementsCount.defaultValue)")
38 | }
39 | }
40 |
41 |
--------------------------------------------------------------------------------
/Example App/FeatureFlagsExample/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE)
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | 1
21 | LSRequiresIPhoneOS
22 |
23 | UIApplicationSceneManifest
24 |
25 | UIApplicationSupportsMultipleScenes
26 |
27 | UISceneConfigurations
28 |
29 | UIWindowSceneSessionRoleApplication
30 |
31 |
32 | UISceneConfigurationName
33 | Default Configuration
34 | UISceneDelegateClassName
35 | $(PRODUCT_MODULE_NAME).SceneDelegate
36 |
37 |
38 |
39 |
40 | UIApplicationSupportsIndirectInputEvents
41 |
42 | UILaunchStoryboardName
43 | LaunchScreen
44 | UIRequiredDeviceCapabilities
45 |
46 | armv7
47 |
48 | UISupportedInterfaceOrientations
49 |
50 | UIInterfaceOrientationPortrait
51 | UIInterfaceOrientationLandscapeLeft
52 | UIInterfaceOrientationLandscapeRight
53 |
54 | UISupportedInterfaceOrientations~ipad
55 |
56 | UIInterfaceOrientationPortrait
57 | UIInterfaceOrientationPortraitUpsideDown
58 | UIInterfaceOrientationLandscapeLeft
59 | UIInterfaceOrientationLandscapeRight
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/Example App/FeatureFlagsExample/RemoteFeatureFlag.swift:
--------------------------------------------------------------------------------
1 | /*
2 | * Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
3 | * This product includes software developed at Datadog (https://www.datadoghq.com/).
4 | * Copyright 2020 Datadog, Inc.
5 | */
6 |
7 | import Foundation
8 | import SwiftUI
9 | import Combine
10 | import FeatureFlagsController
11 |
12 | /// Fake "Remote Feature Flag" illustrating how one can implement a custom feature flag.
13 | ///
14 | /// From this, it should be quite easy to integrate a 3rd party service like Firebase Remote Config or Launch Darkly
15 | public struct RemoteToggleFeatureFlag: FeatureFlagType {
16 |
17 | public init(key: String, group: String? = nil) {
18 | self.id = "RemoteFeatureFlag_\(key)"
19 | self.title = key
20 | self.group = group
21 | }
22 |
23 | public let id: String
24 | public let title: String
25 | public let group: String?
26 |
27 | public var value: Bool {
28 | get { true } // Stub
29 | nonmutating set { }
30 | }
31 |
32 | public var valuePublisher: AnyPublisher {
33 | Empty(completeImmediately: true).eraseToAnyPublisher() // Stub
34 | }
35 |
36 | public var view: some View {
37 | HStack {
38 | Text(title)
39 | Spacer()
40 | Text(value ? "true" : "false").foregroundColor(.secondary)
41 | }
42 | }
43 | }
44 |
45 | extension FeatureFlagType {
46 | public static func remoteToggle(
47 | key: String, group: String? = nil
48 | ) -> Self where Self == RemoteToggleFeatureFlag {
49 | RemoteToggleFeatureFlag(key: key, group: group)
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/Example App/FeatureFlagsExample/SceneDelegate.swift:
--------------------------------------------------------------------------------
1 | /*
2 | * Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
3 | * This product includes software developed at Datadog (https://www.datadoghq.com/).
4 | * Copyright 2020 Datadog, Inc.
5 | */
6 |
7 | import UIKit
8 |
9 | import UIKit
10 | import SwiftUI
11 | import Combine
12 | import FeatureFlagsController
13 |
14 | class SceneDelegate: UIResponder, UIWindowSceneDelegate {
15 |
16 | var window: UIWindow?
17 |
18 | private var cancellables = Set()
19 |
20 | func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
21 | guard let windowScene = scene as? UIWindowScene else {
22 | return
23 | }
24 |
25 | let window = UIWindow(windowScene: windowScene)
26 | let tabBarController = UITabBarController()
27 |
28 | let exampleTab = UINavigationController(rootViewController: Example1ViewController())
29 | exampleTab.tabBarItem = UITabBarItem(title: "UIKit Ex.", image: UIImage(systemName: "eye"), tag: 0)
30 |
31 |
32 | let featureFlagsTab = UIHostingController(rootView: FeatureFlagsView())
33 | featureFlagsTab.tabBarItem = UITabBarItem(title: "Feature Flags", image: UIImage(systemName: "slider.horizontal.below.rectangle"), tag: 2)
34 |
35 | if #available(iOS 14, *) {
36 | let swiftUIExampleTab = UINavigationController(rootViewController: UIHostingController(rootView: Example3View()))
37 | swiftUIExampleTab.navigationBar.prefersLargeTitles = true
38 | swiftUIExampleTab.tabBarItem = UITabBarItem(title: "SwiftUI Ex.", image: UIImage(systemName: "eye"), tag: 1)
39 |
40 | tabBarController.viewControllers = [exampleTab, swiftUIExampleTab, featureFlagsTab]
41 | } else {
42 | tabBarController.viewControllers = [exampleTab, featureFlagsTab]
43 | }
44 |
45 | window.rootViewController = tabBarController
46 |
47 | self.window = window
48 | window.makeKeyAndVisible()
49 |
50 | setUpDarkModeFeatureFlag()
51 | }
52 |
53 | private func setUpDarkModeFeatureFlag() {
54 | ToggleFeatureFlag(title: "Force Dark Mode", defaultValue: false, group: "System")
55 | .register()
56 | .sink { [unowned self] forceDarkMode in
57 | self.window?.rootViewController?.overrideUserInterfaceStyle = forceDarkMode ? .dark : .unspecified
58 | }
59 | .store(in: &cancellables)
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/FeatureFlagsController.podspec:
--------------------------------------------------------------------------------
1 | Pod::Spec.new do |s|
2 | s.name = "FeatureFlagsController"
3 | s.version = "1.0.1"
4 | s.summary = "Easy Feature Flags management"
5 | s.description = <<-DESC
6 | Register any kind of feature flags (Bool, CaseIterable enum, etc...) in your app and access them automatically at runtime in a nice SwiftUI form.
7 | DESC
8 | s.homepage = "https://github.com/DataDog/FeatureFlagsController-iOS"
9 | s.license = { :type => "MIT", :file => "LICENSE.md" }
10 | s.author = { "Jérôme Alves" => "j.alves@me.com" }
11 | s.social_media_url = ""
12 | s.ios.deployment_target = "13.0"
13 | s.source = { :git => "https://github.com/DataDog/FeatureFlagsController-iOS.git", :tag => s.version.to_s }
14 | s.source_files = "Sources/**/*"
15 | s.swift_versions = ["5.5"]
16 | s.frameworks = "Foundation"
17 | end
18 |
--------------------------------------------------------------------------------
/FeatureFlagsController.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 47;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 52D6D9871BEFF229002C0205 /* FeatureFlagsController.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 52D6D97C1BEFF229002C0205 /* FeatureFlagsController.framework */; };
11 | 7537604E2822DAED00C373E6 /* FeatureFlag.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7537604D2822DAEC00C373E6 /* FeatureFlag.swift */; };
12 | 753760532822E17B00C373E6 /* CountFeatureFlag.swift in Sources */ = {isa = PBXBuildFile; fileRef = 753760522822E17B00C373E6 /* CountFeatureFlag.swift */; };
13 | 7561A566251898FB00F405DA /* PickerFeatureFlag.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7561A560251898FA00F405DA /* PickerFeatureFlag.swift */; };
14 | 7561A567251898FB00F405DA /* FeatureFlagType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7561A561251898FB00F405DA /* FeatureFlagType.swift */; };
15 | 7561A568251898FB00F405DA /* FeatureFlagsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7561A562251898FB00F405DA /* FeatureFlagsController.swift */; };
16 | 7561A569251898FB00F405DA /* ToggleFeatureFlag.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7561A563251898FB00F405DA /* ToggleFeatureFlag.swift */; };
17 | 7561A56A251898FB00F405DA /* FeatureFlagsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7561A564251898FB00F405DA /* FeatureFlagsView.swift */; };
18 | 7561A56B251898FB00F405DA /* FeatureFlagViewFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7561A565251898FB00F405DA /* FeatureFlagViewFactory.swift */; };
19 | 7561A5862518A7CC00F405DA /* FeatureFlagsGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7561A5852518A7CC00F405DA /* FeatureFlagsGroup.swift */; };
20 | 8933C7901EB5B82D000D00A4 /* FeatureFlagsControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8933C7891EB5B82A000D00A4 /* FeatureFlagsControllerTests.swift */; };
21 | /* End PBXBuildFile section */
22 |
23 | /* Begin PBXContainerItemProxy section */
24 | 52D6D9881BEFF229002C0205 /* PBXContainerItemProxy */ = {
25 | isa = PBXContainerItemProxy;
26 | containerPortal = 52D6D9731BEFF229002C0205 /* Project object */;
27 | proxyType = 1;
28 | remoteGlobalIDString = 52D6D97B1BEFF229002C0205;
29 | remoteInfo = FeatureFlagsController;
30 | };
31 | /* End PBXContainerItemProxy section */
32 |
33 | /* Begin PBXFileReference section */
34 | 52D6D97C1BEFF229002C0205 /* FeatureFlagsController.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = FeatureFlagsController.framework; sourceTree = BUILT_PRODUCTS_DIR; };
35 | 52D6D9861BEFF229002C0205 /* FeatureFlagsController-iOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "FeatureFlagsController-iOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
36 | 7537604D2822DAEC00C373E6 /* FeatureFlag.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeatureFlag.swift; sourceTree = ""; };
37 | 753760522822E17B00C373E6 /* CountFeatureFlag.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CountFeatureFlag.swift; sourceTree = ""; };
38 | 7561A560251898FA00F405DA /* PickerFeatureFlag.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PickerFeatureFlag.swift; sourceTree = ""; };
39 | 7561A561251898FB00F405DA /* FeatureFlagType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FeatureFlagType.swift; sourceTree = ""; };
40 | 7561A562251898FB00F405DA /* FeatureFlagsController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FeatureFlagsController.swift; sourceTree = ""; };
41 | 7561A563251898FB00F405DA /* ToggleFeatureFlag.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ToggleFeatureFlag.swift; sourceTree = ""; };
42 | 7561A564251898FB00F405DA /* FeatureFlagsView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FeatureFlagsView.swift; sourceTree = ""; };
43 | 7561A565251898FB00F405DA /* FeatureFlagViewFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FeatureFlagViewFactory.swift; sourceTree = ""; };
44 | 7561A5852518A7CC00F405DA /* FeatureFlagsGroup.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FeatureFlagsGroup.swift; sourceTree = ""; };
45 | 8933C7891EB5B82A000D00A4 /* FeatureFlagsControllerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FeatureFlagsControllerTests.swift; sourceTree = ""; };
46 | AD2FAA261CD0B6D800659CF4 /* FeatureFlagsController.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = FeatureFlagsController.plist; sourceTree = ""; };
47 | AD2FAA281CD0B6E100659CF4 /* FeatureFlagsControllerTests.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = FeatureFlagsControllerTests.plist; sourceTree = ""; };
48 | /* End PBXFileReference section */
49 |
50 | /* Begin PBXFrameworksBuildPhase section */
51 | 52D6D9781BEFF229002C0205 /* Frameworks */ = {
52 | isa = PBXFrameworksBuildPhase;
53 | buildActionMask = 2147483647;
54 | files = (
55 | );
56 | runOnlyForDeploymentPostprocessing = 0;
57 | };
58 | 52D6D9831BEFF229002C0205 /* Frameworks */ = {
59 | isa = PBXFrameworksBuildPhase;
60 | buildActionMask = 2147483647;
61 | files = (
62 | 52D6D9871BEFF229002C0205 /* FeatureFlagsController.framework in Frameworks */,
63 | );
64 | runOnlyForDeploymentPostprocessing = 0;
65 | };
66 | /* End PBXFrameworksBuildPhase section */
67 |
68 | /* Begin PBXGroup section */
69 | 52D6D9721BEFF229002C0205 = {
70 | isa = PBXGroup;
71 | children = (
72 | 8933C7811EB5B7E0000D00A4 /* Sources */,
73 | 8933C7831EB5B7EB000D00A4 /* Tests */,
74 | 52D6D99C1BEFF38C002C0205 /* Configs */,
75 | 52D6D97D1BEFF229002C0205 /* Products */,
76 | );
77 | sourceTree = "";
78 | };
79 | 52D6D97D1BEFF229002C0205 /* Products */ = {
80 | isa = PBXGroup;
81 | children = (
82 | 52D6D97C1BEFF229002C0205 /* FeatureFlagsController.framework */,
83 | 52D6D9861BEFF229002C0205 /* FeatureFlagsController-iOS Tests.xctest */,
84 | );
85 | name = Products;
86 | sourceTree = "";
87 | };
88 | 52D6D99C1BEFF38C002C0205 /* Configs */ = {
89 | isa = PBXGroup;
90 | children = (
91 | DD7502721C68FC1B006590AF /* Frameworks */,
92 | DD7502731C68FC20006590AF /* Tests */,
93 | );
94 | path = Configs;
95 | sourceTree = "";
96 | };
97 | 7561A5702518990500F405DA /* Flag Types */ = {
98 | isa = PBXGroup;
99 | children = (
100 | 753760522822E17B00C373E6 /* CountFeatureFlag.swift */,
101 | 7561A563251898FB00F405DA /* ToggleFeatureFlag.swift */,
102 | 7561A560251898FA00F405DA /* PickerFeatureFlag.swift */,
103 | 7561A5852518A7CC00F405DA /* FeatureFlagsGroup.swift */,
104 | );
105 | path = "Flag Types";
106 | sourceTree = "";
107 | };
108 | 7561A5732518991200F405DA /* UI */ = {
109 | isa = PBXGroup;
110 | children = (
111 | 7561A564251898FB00F405DA /* FeatureFlagsView.swift */,
112 | 7561A565251898FB00F405DA /* FeatureFlagViewFactory.swift */,
113 | );
114 | path = UI;
115 | sourceTree = "";
116 | };
117 | 8933C7811EB5B7E0000D00A4 /* Sources */ = {
118 | isa = PBXGroup;
119 | children = (
120 | 7537604D2822DAEC00C373E6 /* FeatureFlag.swift */,
121 | 7561A561251898FB00F405DA /* FeatureFlagType.swift */,
122 | 7561A562251898FB00F405DA /* FeatureFlagsController.swift */,
123 | 7561A5732518991200F405DA /* UI */,
124 | 7561A5702518990500F405DA /* Flag Types */,
125 | );
126 | name = Sources;
127 | path = Sources/FeatureFlagsController;
128 | sourceTree = "";
129 | };
130 | 8933C7831EB5B7EB000D00A4 /* Tests */ = {
131 | isa = PBXGroup;
132 | children = (
133 | 8933C7891EB5B82A000D00A4 /* FeatureFlagsControllerTests.swift */,
134 | );
135 | name = Tests;
136 | path = Tests/FeatureFlagsControllerTests;
137 | sourceTree = "";
138 | };
139 | DD7502721C68FC1B006590AF /* Frameworks */ = {
140 | isa = PBXGroup;
141 | children = (
142 | AD2FAA261CD0B6D800659CF4 /* FeatureFlagsController.plist */,
143 | );
144 | name = Frameworks;
145 | sourceTree = "";
146 | };
147 | DD7502731C68FC20006590AF /* Tests */ = {
148 | isa = PBXGroup;
149 | children = (
150 | AD2FAA281CD0B6E100659CF4 /* FeatureFlagsControllerTests.plist */,
151 | );
152 | name = Tests;
153 | sourceTree = "";
154 | };
155 | /* End PBXGroup section */
156 |
157 | /* Begin PBXHeadersBuildPhase section */
158 | 52D6D9791BEFF229002C0205 /* Headers */ = {
159 | isa = PBXHeadersBuildPhase;
160 | buildActionMask = 2147483647;
161 | files = (
162 | );
163 | runOnlyForDeploymentPostprocessing = 0;
164 | };
165 | /* End PBXHeadersBuildPhase section */
166 |
167 | /* Begin PBXNativeTarget section */
168 | 52D6D97B1BEFF229002C0205 /* FeatureFlagsController-iOS */ = {
169 | isa = PBXNativeTarget;
170 | buildConfigurationList = 52D6D9901BEFF229002C0205 /* Build configuration list for PBXNativeTarget "FeatureFlagsController-iOS" */;
171 | buildPhases = (
172 | 52D6D9771BEFF229002C0205 /* Sources */,
173 | 52D6D9781BEFF229002C0205 /* Frameworks */,
174 | 52D6D9791BEFF229002C0205 /* Headers */,
175 | 52D6D97A1BEFF229002C0205 /* Resources */,
176 | );
177 | buildRules = (
178 | );
179 | dependencies = (
180 | );
181 | name = "FeatureFlagsController-iOS";
182 | productName = FeatureFlagsController;
183 | productReference = 52D6D97C1BEFF229002C0205 /* FeatureFlagsController.framework */;
184 | productType = "com.apple.product-type.framework";
185 | };
186 | 52D6D9851BEFF229002C0205 /* FeatureFlagsController-iOS Tests */ = {
187 | isa = PBXNativeTarget;
188 | buildConfigurationList = 52D6D9931BEFF229002C0205 /* Build configuration list for PBXNativeTarget "FeatureFlagsController-iOS Tests" */;
189 | buildPhases = (
190 | 52D6D9821BEFF229002C0205 /* Sources */,
191 | 52D6D9831BEFF229002C0205 /* Frameworks */,
192 | 52D6D9841BEFF229002C0205 /* Resources */,
193 | );
194 | buildRules = (
195 | );
196 | dependencies = (
197 | 52D6D9891BEFF229002C0205 /* PBXTargetDependency */,
198 | );
199 | name = "FeatureFlagsController-iOS Tests";
200 | productName = FeatureFlagsControllerTests;
201 | productReference = 52D6D9861BEFF229002C0205 /* FeatureFlagsController-iOS Tests.xctest */;
202 | productType = "com.apple.product-type.bundle.unit-test";
203 | };
204 | /* End PBXNativeTarget section */
205 |
206 | /* Begin PBXProject section */
207 | 52D6D9731BEFF229002C0205 /* Project object */ = {
208 | isa = PBXProject;
209 | attributes = {
210 | LastSwiftUpdateCheck = 0720;
211 | LastUpgradeCheck = 1200;
212 | ORGANIZATIONNAME = Datadog;
213 | TargetAttributes = {
214 | 52D6D97B1BEFF229002C0205 = {
215 | CreatedOnToolsVersion = 7.1;
216 | LastSwiftMigration = 1200;
217 | };
218 | 52D6D9851BEFF229002C0205 = {
219 | CreatedOnToolsVersion = 7.1;
220 | LastSwiftMigration = 1020;
221 | };
222 | };
223 | };
224 | buildConfigurationList = 52D6D9761BEFF229002C0205 /* Build configuration list for PBXProject "FeatureFlagsController" */;
225 | compatibilityVersion = "Xcode 6.3";
226 | developmentRegion = en;
227 | hasScannedForEncodings = 0;
228 | knownRegions = (
229 | en,
230 | Base,
231 | );
232 | mainGroup = 52D6D9721BEFF229002C0205;
233 | productRefGroup = 52D6D97D1BEFF229002C0205 /* Products */;
234 | projectDirPath = "";
235 | projectRoot = "";
236 | targets = (
237 | 52D6D97B1BEFF229002C0205 /* FeatureFlagsController-iOS */,
238 | 52D6D9851BEFF229002C0205 /* FeatureFlagsController-iOS Tests */,
239 | );
240 | };
241 | /* End PBXProject section */
242 |
243 | /* Begin PBXResourcesBuildPhase section */
244 | 52D6D97A1BEFF229002C0205 /* Resources */ = {
245 | isa = PBXResourcesBuildPhase;
246 | buildActionMask = 2147483647;
247 | files = (
248 | );
249 | runOnlyForDeploymentPostprocessing = 0;
250 | };
251 | 52D6D9841BEFF229002C0205 /* Resources */ = {
252 | isa = PBXResourcesBuildPhase;
253 | buildActionMask = 2147483647;
254 | files = (
255 | );
256 | runOnlyForDeploymentPostprocessing = 0;
257 | };
258 | /* End PBXResourcesBuildPhase section */
259 |
260 | /* Begin PBXSourcesBuildPhase section */
261 | 52D6D9771BEFF229002C0205 /* Sources */ = {
262 | isa = PBXSourcesBuildPhase;
263 | buildActionMask = 2147483647;
264 | files = (
265 | 753760532822E17B00C373E6 /* CountFeatureFlag.swift in Sources */,
266 | 7561A56B251898FB00F405DA /* FeatureFlagViewFactory.swift in Sources */,
267 | 7561A567251898FB00F405DA /* FeatureFlagType.swift in Sources */,
268 | 7537604E2822DAED00C373E6 /* FeatureFlag.swift in Sources */,
269 | 7561A56A251898FB00F405DA /* FeatureFlagsView.swift in Sources */,
270 | 7561A5862518A7CC00F405DA /* FeatureFlagsGroup.swift in Sources */,
271 | 7561A566251898FB00F405DA /* PickerFeatureFlag.swift in Sources */,
272 | 7561A569251898FB00F405DA /* ToggleFeatureFlag.swift in Sources */,
273 | 7561A568251898FB00F405DA /* FeatureFlagsController.swift in Sources */,
274 | );
275 | runOnlyForDeploymentPostprocessing = 0;
276 | };
277 | 52D6D9821BEFF229002C0205 /* Sources */ = {
278 | isa = PBXSourcesBuildPhase;
279 | buildActionMask = 2147483647;
280 | files = (
281 | 8933C7901EB5B82D000D00A4 /* FeatureFlagsControllerTests.swift in Sources */,
282 | );
283 | runOnlyForDeploymentPostprocessing = 0;
284 | };
285 | /* End PBXSourcesBuildPhase section */
286 |
287 | /* Begin PBXTargetDependency section */
288 | 52D6D9891BEFF229002C0205 /* PBXTargetDependency */ = {
289 | isa = PBXTargetDependency;
290 | target = 52D6D97B1BEFF229002C0205 /* FeatureFlagsController-iOS */;
291 | targetProxy = 52D6D9881BEFF229002C0205 /* PBXContainerItemProxy */;
292 | };
293 | /* End PBXTargetDependency section */
294 |
295 | /* Begin XCBuildConfiguration section */
296 | 52D6D98E1BEFF229002C0205 /* Debug */ = {
297 | isa = XCBuildConfiguration;
298 | buildSettings = {
299 | ALWAYS_SEARCH_USER_PATHS = NO;
300 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
301 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
302 | CLANG_CXX_LIBRARY = "libc++";
303 | CLANG_ENABLE_MODULES = YES;
304 | CLANG_ENABLE_OBJC_ARC = YES;
305 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
306 | CLANG_WARN_BOOL_CONVERSION = YES;
307 | CLANG_WARN_COMMA = YES;
308 | CLANG_WARN_CONSTANT_CONVERSION = YES;
309 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
310 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
311 | CLANG_WARN_EMPTY_BODY = YES;
312 | CLANG_WARN_ENUM_CONVERSION = YES;
313 | CLANG_WARN_INFINITE_RECURSION = YES;
314 | CLANG_WARN_INT_CONVERSION = YES;
315 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
316 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
317 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
318 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
319 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
320 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
321 | CLANG_WARN_STRICT_PROTOTYPES = YES;
322 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
323 | CLANG_WARN_UNREACHABLE_CODE = YES;
324 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
325 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
326 | COPY_PHASE_STRIP = NO;
327 | CURRENT_PROJECT_VERSION = 1;
328 | DEBUG_INFORMATION_FORMAT = dwarf;
329 | ENABLE_STRICT_OBJC_MSGSEND = YES;
330 | ENABLE_TESTABILITY = YES;
331 | GCC_C_LANGUAGE_STANDARD = gnu99;
332 | GCC_DYNAMIC_NO_PIC = NO;
333 | GCC_NO_COMMON_BLOCKS = YES;
334 | GCC_OPTIMIZATION_LEVEL = 0;
335 | GCC_PREPROCESSOR_DEFINITIONS = (
336 | "DEBUG=1",
337 | "$(inherited)",
338 | );
339 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
340 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
341 | GCC_WARN_UNDECLARED_SELECTOR = YES;
342 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
343 | GCC_WARN_UNUSED_FUNCTION = YES;
344 | GCC_WARN_UNUSED_VARIABLE = YES;
345 | IPHONEOS_DEPLOYMENT_TARGET = 13.0;
346 | MTL_ENABLE_DEBUG_INFO = YES;
347 | ONLY_ACTIVE_ARCH = YES;
348 | SDKROOT = iphoneos;
349 | SWIFT_OPTIMIZATION_LEVEL = "-Onone";
350 | SWIFT_VERSION = 5.0;
351 | TARGETED_DEVICE_FAMILY = "1,2";
352 | VERSIONING_SYSTEM = "apple-generic";
353 | VERSION_INFO_PREFIX = "";
354 | };
355 | name = Debug;
356 | };
357 | 52D6D98F1BEFF229002C0205 /* Release */ = {
358 | isa = XCBuildConfiguration;
359 | buildSettings = {
360 | ALWAYS_SEARCH_USER_PATHS = NO;
361 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
362 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
363 | CLANG_CXX_LIBRARY = "libc++";
364 | CLANG_ENABLE_MODULES = YES;
365 | CLANG_ENABLE_OBJC_ARC = YES;
366 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
367 | CLANG_WARN_BOOL_CONVERSION = YES;
368 | CLANG_WARN_COMMA = YES;
369 | CLANG_WARN_CONSTANT_CONVERSION = YES;
370 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
371 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
372 | CLANG_WARN_EMPTY_BODY = YES;
373 | CLANG_WARN_ENUM_CONVERSION = YES;
374 | CLANG_WARN_INFINITE_RECURSION = YES;
375 | CLANG_WARN_INT_CONVERSION = YES;
376 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
377 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
378 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
379 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
380 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
381 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
382 | CLANG_WARN_STRICT_PROTOTYPES = YES;
383 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
384 | CLANG_WARN_UNREACHABLE_CODE = YES;
385 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
386 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
387 | COPY_PHASE_STRIP = NO;
388 | CURRENT_PROJECT_VERSION = 1;
389 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
390 | ENABLE_NS_ASSERTIONS = NO;
391 | ENABLE_STRICT_OBJC_MSGSEND = YES;
392 | GCC_C_LANGUAGE_STANDARD = gnu99;
393 | GCC_NO_COMMON_BLOCKS = YES;
394 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
395 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
396 | GCC_WARN_UNDECLARED_SELECTOR = YES;
397 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
398 | GCC_WARN_UNUSED_FUNCTION = YES;
399 | GCC_WARN_UNUSED_VARIABLE = YES;
400 | IPHONEOS_DEPLOYMENT_TARGET = 13.0;
401 | MTL_ENABLE_DEBUG_INFO = NO;
402 | SDKROOT = iphoneos;
403 | SWIFT_VERSION = 5.0;
404 | TARGETED_DEVICE_FAMILY = "1,2";
405 | VALIDATE_PRODUCT = YES;
406 | VERSIONING_SYSTEM = "apple-generic";
407 | VERSION_INFO_PREFIX = "";
408 | };
409 | name = Release;
410 | };
411 | 52D6D9911BEFF229002C0205 /* Debug */ = {
412 | isa = XCBuildConfiguration;
413 | buildSettings = {
414 | APPLICATION_EXTENSION_API_ONLY = YES;
415 | CLANG_ENABLE_MODULES = YES;
416 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
417 | DEFINES_MODULE = YES;
418 | DYLIB_COMPATIBILITY_VERSION = 1;
419 | DYLIB_CURRENT_VERSION = 1;
420 | DYLIB_INSTALL_NAME_BASE = "@rpath";
421 | INFOPLIST_FILE = Configs/FeatureFlagsController.plist;
422 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
423 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
424 | ONLY_ACTIVE_ARCH = NO;
425 | PRODUCT_BUNDLE_IDENTIFIER = "com.FeatureFlagsController.FeatureFlagsController-iOS";
426 | PRODUCT_NAME = FeatureFlagsController;
427 | SKIP_INSTALL = YES;
428 | SWIFT_OPTIMIZATION_LEVEL = "-Onone";
429 | SWIFT_VERSION = 5.0;
430 | };
431 | name = Debug;
432 | };
433 | 52D6D9921BEFF229002C0205 /* Release */ = {
434 | isa = XCBuildConfiguration;
435 | buildSettings = {
436 | APPLICATION_EXTENSION_API_ONLY = YES;
437 | CLANG_ENABLE_MODULES = YES;
438 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
439 | DEFINES_MODULE = YES;
440 | DYLIB_COMPATIBILITY_VERSION = 1;
441 | DYLIB_CURRENT_VERSION = 1;
442 | DYLIB_INSTALL_NAME_BASE = "@rpath";
443 | INFOPLIST_FILE = Configs/FeatureFlagsController.plist;
444 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
445 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
446 | PRODUCT_BUNDLE_IDENTIFIER = "com.FeatureFlagsController.FeatureFlagsController-iOS";
447 | PRODUCT_NAME = FeatureFlagsController;
448 | SKIP_INSTALL = YES;
449 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
450 | SWIFT_VERSION = 5.0;
451 | };
452 | name = Release;
453 | };
454 | 52D6D9941BEFF229002C0205 /* Debug */ = {
455 | isa = XCBuildConfiguration;
456 | buildSettings = {
457 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
458 | CLANG_ENABLE_MODULES = YES;
459 | INFOPLIST_FILE = Configs/FeatureFlagsControllerTests.plist;
460 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
461 | PRODUCT_BUNDLE_IDENTIFIER = "com.FeatureFlagsController.FeatureFlagsController-iOS-Tests";
462 | PRODUCT_NAME = "$(TARGET_NAME)";
463 | SWIFT_OPTIMIZATION_LEVEL = "-Onone";
464 | SWIFT_VERSION = 5.0;
465 | };
466 | name = Debug;
467 | };
468 | 52D6D9951BEFF229002C0205 /* Release */ = {
469 | isa = XCBuildConfiguration;
470 | buildSettings = {
471 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
472 | CLANG_ENABLE_MODULES = YES;
473 | INFOPLIST_FILE = Configs/FeatureFlagsControllerTests.plist;
474 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
475 | PRODUCT_BUNDLE_IDENTIFIER = "com.FeatureFlagsController.FeatureFlagsController-iOS-Tests";
476 | PRODUCT_NAME = "$(TARGET_NAME)";
477 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
478 | SWIFT_VERSION = 5.0;
479 | };
480 | name = Release;
481 | };
482 | /* End XCBuildConfiguration section */
483 |
484 | /* Begin XCConfigurationList section */
485 | 52D6D9761BEFF229002C0205 /* Build configuration list for PBXProject "FeatureFlagsController" */ = {
486 | isa = XCConfigurationList;
487 | buildConfigurations = (
488 | 52D6D98E1BEFF229002C0205 /* Debug */,
489 | 52D6D98F1BEFF229002C0205 /* Release */,
490 | );
491 | defaultConfigurationIsVisible = 0;
492 | defaultConfigurationName = Release;
493 | };
494 | 52D6D9901BEFF229002C0205 /* Build configuration list for PBXNativeTarget "FeatureFlagsController-iOS" */ = {
495 | isa = XCConfigurationList;
496 | buildConfigurations = (
497 | 52D6D9911BEFF229002C0205 /* Debug */,
498 | 52D6D9921BEFF229002C0205 /* Release */,
499 | );
500 | defaultConfigurationIsVisible = 0;
501 | defaultConfigurationName = Release;
502 | };
503 | 52D6D9931BEFF229002C0205 /* Build configuration list for PBXNativeTarget "FeatureFlagsController-iOS Tests" */ = {
504 | isa = XCConfigurationList;
505 | buildConfigurations = (
506 | 52D6D9941BEFF229002C0205 /* Debug */,
507 | 52D6D9951BEFF229002C0205 /* Release */,
508 | );
509 | defaultConfigurationIsVisible = 0;
510 | defaultConfigurationName = Release;
511 | };
512 | /* End XCConfigurationList section */
513 | };
514 | rootObject = 52D6D9731BEFF229002C0205 /* Project object */;
515 | }
516 |
--------------------------------------------------------------------------------
/FeatureFlagsController.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/FeatureFlagsController.xcodeproj/xcshareddata/xcschemes/FeatureFlagsController-iOS.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
31 |
32 |
38 |
39 |
40 |
41 |
43 |
49 |
50 |
51 |
52 |
53 |
63 |
64 |
70 |
71 |
72 |
73 |
79 |
80 |
86 |
87 |
88 |
89 |
91 |
92 |
95 |
96 |
97 |
--------------------------------------------------------------------------------
/FeatureFlagsController.xcodeproj/xcshareddata/xcschemes/FeatureFlagsController-macOS.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
31 |
32 |
38 |
39 |
40 |
41 |
43 |
49 |
50 |
51 |
52 |
53 |
63 |
64 |
70 |
71 |
72 |
73 |
79 |
80 |
86 |
87 |
88 |
89 |
91 |
92 |
95 |
96 |
97 |
--------------------------------------------------------------------------------
/FeatureFlagsController.xcodeproj/xcshareddata/xcschemes/FeatureFlagsController-tvOS.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
31 |
32 |
38 |
39 |
40 |
41 |
43 |
49 |
50 |
51 |
52 |
53 |
63 |
64 |
70 |
71 |
72 |
73 |
79 |
80 |
86 |
87 |
88 |
89 |
91 |
92 |
95 |
96 |
97 |
--------------------------------------------------------------------------------
/FeatureFlagsController.xcodeproj/xcshareddata/xcschemes/FeatureFlagsController-watchOS.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
31 |
32 |
33 |
34 |
44 |
45 |
51 |
52 |
53 |
54 |
60 |
61 |
67 |
68 |
69 |
70 |
72 |
73 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Datadog, Inc.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Package.swift:
--------------------------------------------------------------------------------
1 | // swift-tools-version:5.5
2 | // The swift-tools-version declares the minimum version of Swift required to build this package.
3 |
4 | import PackageDescription
5 |
6 | let package = Package(
7 | name: "FeatureFlagsController",
8 | platforms: [
9 | .iOS(.v13),
10 | ],
11 | products: [
12 | // Products define the executables and libraries produced by a package, and make them visible to other packages.
13 | .library(
14 | name: "FeatureFlagsController",
15 | targets: ["FeatureFlagsController"]),
16 | ],
17 | dependencies: [
18 | // Dependencies declare other packages that this package depends on.
19 | // .package(url: /* package url */, from: "1.0.0"),
20 | ],
21 | targets: [
22 | // Targets are the basic building blocks of a package. A target can define a module or a test suite.
23 | // Targets can depend on other targets in this package, and on products in packages which this package depends on.
24 | .target(
25 | name: "FeatureFlagsController",
26 | dependencies: []),
27 | .testTarget(
28 | name: "FeatureFlagsControllerTests",
29 | dependencies: ["FeatureFlagsController"]),
30 | ]
31 | )
32 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # FeatureFlagsController
2 |
3 | 
4 |
5 |
6 | FeatureFlagsController is a micro-library to automatically build a SwiftUI Form View from all registered feature flags in a project, leveraging power of functional reactive programming using Combine.
7 |
8 |
9 | ## Requirements
10 | - iOS 13.0+
11 | - Xcode 13.0+
12 | - Swift 5.5+
13 |
14 |
15 | ## Installation
16 |
17 | ### CocoaPods
18 |
19 | Add the following to your `Podfile`:
20 |
21 | `pod "FeatureFlagsController"`
22 |
23 |
24 | ### Swift Package Manager
25 |
26 | `https://github.com/DataDog/FeatureFlagsController` using Xcode 12 SPM integration
27 |
28 |
29 | ## Usage
30 |
31 | ### FeatureFlagsView
32 |
33 | All registered feature flags appear in a `FeatureFlagsView` which is a `SwiftUI.View` composed of a `NavigationView` and a sectioned `Form`.
34 | You can display this view anywhere in your application. In a hidden "debug" menu for example.
35 |
36 | This form keeps track of registered feature flags and display the right UI to modify them at runtime. A `ToggleFeatureFlag` will display a simple `Toggle` (`UISwitch`) while a `PickerFeatureFlag` will display a segmented control or a sub-menu depending the picker style it is given.
37 |
38 | ### Declaration
39 |
40 | Here is how you declare a new Feature Flag:
41 |
42 | ```swift
43 | let roundedCornersFeatureFlag = ToggleFeatureFlag(
44 | title: "Rounded Corners", defaultValue: true, group: "Home Screen"
45 | )
46 | ```
47 |
48 | Declaring a feature flag doesn't do anything on its own, but you still can access its value using the `value` property. Some feature flags types have an alias to the `value` property to make the call-site more clear. For example, the `ToggleFeatureFlag` has the `isEnabled` alias.
49 |
50 | ### Registration
51 |
52 | In order to display a feature flag in the `FeatureFlagsView`, a feature flag must be registered. The `register()` methods return a Combine `AnyPublisher` emitting immediately the current value, then all value updates.
53 |
54 | Once the Combine subscription is cancelled (for example, when the owning view controller is popped or dismissed), the feature flag disappears from the `FeatureFlagsView`.
55 |
56 | ```swift
57 | roundedCornersFeatureFlag
58 | .register() // Adds the feature flag to the `FeatureFlagsView` and returns an AnyPublisher
59 | .map { $0 ? 16 : 0 } // Use all Combine operators you want to
60 | .assign(to: \.cornerRadius, on: squareView.layer)
61 | .store(in: &cancellables) // On cancellation, the feature flag is removed from the `FeatureFlagsView`
62 | ```
63 |
64 | ### SwiftUI
65 |
66 | In SwiftUI, it's even simpler. You can just use the `@FeatureFlag` property wrapper, either by passing a declared feature flag, or by using a convenience init.
67 | ```swift
68 | static let roundedCornersFeatureFlag = ToggleFeatureFlag(
69 | title: "Rounded Corners", defaultValue: true, group: "Home Screen"
70 | )
71 |
72 | @FeatureFlag(Self.roundedCornersFeatureFlag) var hasRoundedCorners
73 | ```
74 | Or...
75 | ```swift
76 | @FeatureFlag(title: "Rounded Corners", group: "Home Screen")
77 | var hasRoundedCorners = true
78 | ```
79 |
80 | You can also use the projected value to get the underlying feature flag:
81 | ```swift
82 | Text($hasRoundedCorners.title)
83 | ```
84 |
85 | ## License
86 |
87 | This framework is provided under the MIT license.
88 |
--------------------------------------------------------------------------------
/Sources/FeatureFlagsController/FeatureFlag.swift:
--------------------------------------------------------------------------------
1 | /*
2 | * Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
3 | * This product includes software developed at Datadog (https://www.datadoghq.com/).
4 | * Copyright 2020 Datadog, Inc.
5 | */
6 |
7 | import SwiftUI
8 | import Combine
9 |
10 | @available(iOS 14, *)
11 | @propertyWrapper
12 | public struct FeatureFlag: DynamicProperty {
13 | @StateObject private var registration: Registration
14 | private let featureFlag: F
15 |
16 | public var wrappedValue: F.Value {
17 | registration.value
18 | }
19 |
20 | public var projectedValue: F {
21 | featureFlag
22 | }
23 |
24 | public init(_ featureFlag: F) {
25 | self.featureFlag = featureFlag
26 | self._registration = StateObject(wrappedValue: Registration(featureFlag))
27 | }
28 |
29 | private class Registration: ObservableObject {
30 |
31 | @Published var value: F.Value
32 |
33 | private var cancellable: AnyCancellable?
34 |
35 | init(_ featureFlag: F) {
36 | value = featureFlag.value
37 | cancellable = featureFlag.register().sink(receiveValue: { [weak self] newValue in
38 | self?.value = newValue
39 | })
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/Sources/FeatureFlagsController/FeatureFlagType.swift:
--------------------------------------------------------------------------------
1 | /*
2 | * Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
3 | * This product includes software developed at Datadog (https://www.datadoghq.com/).
4 | * Copyright 2020 Datadog, Inc.
5 | */
6 |
7 | import Combine
8 | import Foundation
9 | import SwiftUI
10 | import Combine
11 |
12 | public protocol FeatureFlagType {
13 | associatedtype Value: Equatable
14 | associatedtype View: SwiftUI.View
15 |
16 | var id: String { get }
17 | var title: String { get }
18 | var group: String? { get }
19 | var value: Value { get nonmutating set }
20 | var valuePublisher: AnyPublisher { get }
21 |
22 | var view: View { get }
23 | }
24 |
25 | extension FeatureFlagType {
26 |
27 | public func register() -> AnyPublisher {
28 | FeatureFlagsController.shared.register(self)
29 | }
30 |
31 | public var valueBinding: Binding {
32 | Binding {
33 | self.value
34 | } set: {
35 | self.value = $0
36 | }
37 | }
38 |
39 | public var id: String {
40 | let slugifiedTitle = title
41 | .components(separatedBy:
42 | CharacterSet.alphanumerics.inverted
43 | )
44 | .joined(separator: "-")
45 | return "FeatureFlag_\(slugifiedTitle)"
46 | }
47 |
48 | }
49 |
50 | private var preferredUserDefaults: UserDefaults = .featureFlagsSuite
51 |
52 | extension UserDefaults {
53 | public static var featureFlags: UserDefaults {
54 | get { preferredUserDefaults }
55 | set { preferredUserDefaults = newValue }
56 | }
57 |
58 | public static var featureFlagsSuite: UserDefaults {
59 | guard let bundleIdentifier = Bundle.main.bundleIdentifier else {
60 | return .standard
61 | }
62 | return UserDefaults(suiteName: "\(bundleIdentifier).FeatureFlagsController") ?? .standard
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/Sources/FeatureFlagsController/FeatureFlagsController.swift:
--------------------------------------------------------------------------------
1 | /*
2 | * Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
3 | * This product includes software developed at Datadog (https://www.datadoghq.com/).
4 | * Copyright 2020 Datadog, Inc.
5 | */
6 |
7 | import Foundation
8 | import Combine
9 | import SwiftUI
10 |
11 | internal final class FeatureFlagsController: ObservableObject {
12 | internal static let shared = FeatureFlagsController()
13 |
14 | private init() {}
15 |
16 | internal func register(
17 | _ flag: F
18 | ) -> AnyPublisher {
19 |
20 | if let publisher = publisher(for: flag) {
21 | return publisher
22 | }
23 |
24 | let publisher = flag
25 | .valuePublisher
26 | .handleEvents(
27 | receiveOutput: { _ in self.objectWillChange.send() },
28 | receiveCancel: { self.removePublisher(for: flag) }
29 | )
30 | .share()
31 | .prepend(flag.value)
32 | .removeDuplicates()
33 | .receive(on: DispatchQueue.main)
34 | .eraseToAnyPublisher()
35 |
36 | addPublisher(publisher, for: flag)
37 |
38 | return publisher
39 | }
40 |
41 | // MARK: - Publishers
42 |
43 | @Published
44 | internal var viewFactories: [FeatureFlagViewFactory] = []
45 |
46 | private var publishers: [String: Any] = [:]
47 |
48 | private func publisher(
49 | for flag: F
50 | ) -> AnyPublisher? {
51 | publishers[flag.id] as? AnyPublisher
52 | }
53 |
54 | private func addPublisher(
55 | _ publisher: AnyPublisher,
56 | for flag: F
57 | ) {
58 | if viewFactories.contains(where: { $0.id == flag.id }) == false {
59 | viewFactories.append(FeatureFlagViewFactory(flag))
60 | }
61 | publishers[flag.id] = publisher
62 | }
63 |
64 | private func removePublisher(
65 | for flag: F
66 | ) {
67 | viewFactories.removeAll(where: { $0.id == flag.id })
68 | publishers.removeValue(forKey: flag.id)
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/Sources/FeatureFlagsController/Flag Types/CountFeatureFlag.swift:
--------------------------------------------------------------------------------
1 | /*
2 | * Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
3 | * This product includes software developed at Datadog (https://www.datadoghq.com/).
4 | * Copyright 2020 Datadog, Inc.
5 | */
6 |
7 | import Foundation
8 | import SwiftUI
9 | import Combine
10 |
11 | public struct CountFeatureFlag: FeatureFlagType {
12 | public init(title: String, range: ClosedRange, defaultValue: Int, group: String? = nil, userDefaults: UserDefaults = .featureFlags) {
13 | self.title = title
14 | self.range = range
15 | self.defaultValue = defaultValue.bound(by: range)
16 | self.group = group
17 | self.userDefaults = userDefaults
18 | }
19 |
20 | public let title: String
21 | public let range: ClosedRange
22 | public let defaultValue: Int
23 | public let group: String?
24 |
25 | private let userDefaults: UserDefaults
26 |
27 | public var value: Int {
28 | get {
29 | guard
30 | let value = userDefaults.object(forKey: id) as? NSNumber
31 | else {
32 | return defaultValue
33 | }
34 | return value.intValue
35 | }
36 | nonmutating set {
37 | userDefaults.set(newValue.bound(by: range), forKey: id)
38 | }
39 | }
40 |
41 | public var valuePublisher: AnyPublisher {
42 | NotificationCenter.default
43 | .publisher(for: UserDefaults.didChangeNotification)
44 | .map { _ in self.value }
45 | .removeDuplicates()
46 | .eraseToAnyPublisher()
47 | }
48 |
49 | public var view: some View {
50 | HStack {
51 | Text(title)
52 | Spacer()
53 | Text(
54 | "\(value)"
55 | )
56 | .bold()
57 | Stepper(
58 | title, value: valueBinding, in: range
59 | )
60 | .labelsHidden()
61 | }
62 | }
63 | }
64 |
65 | extension FeatureFlagType {
66 | public static func count(
67 | title: String, range: ClosedRange, defaultValue: Int, group: String? = nil, userDefaults: UserDefaults = .featureFlags
68 | ) -> Self where Self == CountFeatureFlag {
69 | CountFeatureFlag(title: title, range: range, defaultValue: defaultValue, group: group, userDefaults: userDefaults)
70 | }
71 | }
72 |
73 | @available(iOS 14, *)
74 | extension FeatureFlag {
75 | public init(
76 | wrappedValue: F.Value, title: String, range: ClosedRange, group: String? = nil, userDefaults: UserDefaults = .featureFlags
77 | ) where F == CountFeatureFlag {
78 | self.init(CountFeatureFlag(title: title, range: range, defaultValue: wrappedValue, group: group, userDefaults: userDefaults))
79 | }
80 | }
81 |
82 | extension Int {
83 | fileprivate func bound(by range: ClosedRange) -> Int {
84 | Swift.min(Swift.max(range.lowerBound, self), range.upperBound)
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/Sources/FeatureFlagsController/Flag Types/FeatureFlagsGroup.swift:
--------------------------------------------------------------------------------
1 | /*
2 | * Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
3 | * This product includes software developed at Datadog (https://www.datadoghq.com/).
4 | * Copyright 2020 Datadog, Inc.
5 | */
6 |
7 | import Foundation
8 | import SwiftUI
9 | import Combine
10 |
11 | public struct FeatureFlagsGroup: FeatureFlagType where First.Value == Second.Value {
12 |
13 | public init(title: String, first: First, second: Second, group: String? = nil, userDefaults: UserDefaults = .featureFlags) {
14 | self.title = title
15 | self.group = group ?? first.group ?? second.group
16 | self.first = first
17 | self.second = second
18 | self.userDefaults = userDefaults
19 | }
20 |
21 | public let first: First
22 | public let second: Second
23 |
24 | public let title: String
25 | public let group: String?
26 |
27 | fileprivate let userDefaults: UserDefaults
28 |
29 | private var values: [String: Value] {
30 | [first.id: first.value, second.id: second.value]
31 | }
32 |
33 | private var valuePublishers: [String: AnyPublisher] {
34 | [first.id: first.valuePublisher, second.id: second.valuePublisher]
35 | }
36 |
37 | private var activeValuePublisher: AnyPublisher {
38 | valuePublishers[activeFeatureFlagID] ?? first.valuePublisher
39 | }
40 |
41 | public typealias Value = First.Value
42 | public var value: Value {
43 | get { values[activeFeatureFlagID] ?? first.value }
44 | nonmutating set { }
45 | }
46 |
47 | public var valuePublisher: AnyPublisher {
48 | NotificationCenter.default
49 | .publisher(for: UserDefaults.didChangeNotification)
50 | .map { _ in self.activeFeatureFlagID }
51 | .prepend(self.activeFeatureFlagID)
52 | .removeDuplicates()
53 | .receive(on: DispatchQueue.main)
54 | .flatMap { _ in
55 | self.activeValuePublisher.prepend(self.value)
56 | }
57 | .eraseToAnyPublisher()
58 | }
59 |
60 | public var view: some View {
61 | NavigationLink(destination: FeatureFlagsGroupDetailView(featureFlag: self)) {
62 | Text(title)
63 | }
64 | }
65 |
66 | fileprivate var activeFeatureFlagID: String {
67 | get {
68 | userDefaults.string(forKey: id + "_activeFeatureFlagID") ?? first.id
69 | }
70 | nonmutating set {
71 | userDefaults.set(newValue, forKey: id + "_activeFeatureFlagID")
72 | }
73 | }
74 |
75 | }
76 |
77 | private struct FeatureFlagsGroupDetailView: View where First.Value == Second.Value {
78 |
79 | let featureFlag: FeatureFlagsGroup
80 |
81 | @State var refreshCount: Int = 0
82 |
83 | private var activeFeatureFlagID: Binding {
84 | Binding {
85 | featureFlag.activeFeatureFlagID
86 | } set: { newValue in
87 | featureFlag.activeFeatureFlagID = newValue
88 | refreshCount += 1
89 | }
90 | }
91 |
92 | var body: some View {
93 | Form {
94 | Section(header: Text("ACTIVE FEATURE FLAG")) {
95 | Picker("", selection: activeFeatureFlagID) {
96 | Text("First").tag(featureFlag.first.id)
97 | Text("Second").tag(featureFlag.second.id)
98 | }
99 | .pickerStyle(SegmentedPickerStyle())
100 | }
101 | Section(header: Text("FIRST FEATURE FLAG")) {
102 | featureFlag.first.view.opacity(activeFeatureFlagID.wrappedValue == featureFlag.first.id ? 1 : 0.5)
103 | }
104 | Section(header: Text("SECOND FEATURE FLAG")) {
105 | featureFlag.second.view.opacity(activeFeatureFlagID.wrappedValue == featureFlag.second.id ? 1 : 0.5)
106 | }
107 | }
108 | .tag(refreshCount)
109 | .navigationBarTitle(featureFlag.title)
110 | }
111 | }
112 |
113 | extension FeatureFlagType {
114 | public static func group(
115 | title: String, first: First, second: Second, group: String? = nil, userDefaults: UserDefaults = .featureFlags
116 | ) -> Self where Self == FeatureFlagsGroup {
117 | FeatureFlagsGroup(title: title, first: first, second: second, group: group, userDefaults: userDefaults)
118 | }
119 | }
120 |
121 | @available(iOS 14, *)
122 | extension FeatureFlag {
123 | public init(
124 | title: String, first: First, second: Second, group: String? = nil, userDefaults: UserDefaults = .featureFlags
125 | ) where F == FeatureFlagsGroup {
126 | self.init(FeatureFlagsGroup(title: title, first: first, second: second, group: group, userDefaults: userDefaults))
127 | }
128 | }
129 |
--------------------------------------------------------------------------------
/Sources/FeatureFlagsController/Flag Types/PickerFeatureFlag.swift:
--------------------------------------------------------------------------------
1 | /*
2 | * Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
3 | * This product includes software developed at Datadog (https://www.datadoghq.com/).
4 | * Copyright 2020 Datadog, Inc.
5 | */
6 |
7 | import Foundation
8 | import SwiftUI
9 | import Combine
10 |
11 | public struct PickerFeatureFlag: FeatureFlagType where
12 | Value: CaseIterable & Hashable & RawRepresentable,
13 | Value.RawValue == String,
14 | Value.AllCases: RandomAccessCollection {
15 |
16 | public init(title: String, defaultValue: Value, group: String? = nil, userDefaults: UserDefaults = .featureFlags, style: Style) {
17 | self.title = title
18 | self.defaultValue = defaultValue
19 | self.group = group
20 | self.userDefaults = userDefaults
21 | self.style = style
22 | }
23 |
24 | private let style: Style
25 | public let title: String
26 | public let defaultValue: Value
27 | public let group: String?
28 | private let userDefaults: UserDefaults
29 |
30 | public var value: Value {
31 | get {
32 | guard let rawValue = userDefaults.object(forKey: id) as? String,
33 | let value = Value.init(rawValue: rawValue)
34 | else {
35 | return defaultValue
36 | }
37 | return value
38 | }
39 | nonmutating set {
40 | userDefaults.set(newValue.rawValue, forKey: id)
41 | }
42 | }
43 |
44 | public var valuePublisher: AnyPublisher {
45 | NotificationCenter.default
46 | .publisher(for: UserDefaults.didChangeNotification)
47 | .map { _ in self.value }
48 | .removeDuplicates()
49 | .eraseToAnyPublisher()
50 | }
51 |
52 | public var view: some View {
53 | HStack(spacing: 16) {
54 | Text(title)
55 | Spacer()
56 | Picker(selection: valueBinding, label: Text("")) {
57 | ForEach(Value.allCases, id: \.hashValue) { value in
58 | value.makeView()
59 | }
60 | }
61 | .pickerStyle(style)
62 | }
63 | }
64 | }
65 |
66 | extension PickerFeatureFlag where Style == DefaultPickerStyle {
67 | public init(title: String, defaultValue: Value, group: String? = nil) {
68 | self = PickerFeatureFlag(title: title, defaultValue: defaultValue, group: group, style: DefaultPickerStyle())
69 | }
70 | }
71 |
72 | extension RawRepresentable where Self: Hashable, RawValue == String {
73 | fileprivate func makeView() -> some View {
74 | Text(String(describing: self)).tag(self)
75 | }
76 | }
77 |
78 |
79 | extension FeatureFlagType {
80 | public static func picker(
81 | title: String, defaultValue: Value, group: String? = nil, userDefaults: UserDefaults = .featureFlags, style: Style
82 | ) -> Self where Self == PickerFeatureFlag {
83 | PickerFeatureFlag(title: title, defaultValue: defaultValue, group: group, userDefaults: userDefaults, style: style)
84 | }
85 | }
86 |
87 | @available(iOS 14, *)
88 | extension FeatureFlag {
89 | public init(
90 | wrappedValue: Value, title: String, group: String? = nil, userDefaults: UserDefaults = .featureFlags, style: Style
91 | ) where F == PickerFeatureFlag {
92 | self.init(PickerFeatureFlag(title: title, defaultValue: wrappedValue, group: group, userDefaults: userDefaults, style: style))
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/Sources/FeatureFlagsController/Flag Types/ToggleFeatureFlag.swift:
--------------------------------------------------------------------------------
1 | /*
2 | * Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
3 | * This product includes software developed at Datadog (https://www.datadoghq.com/).
4 | * Copyright 2020 Datadog, Inc.
5 | */
6 |
7 | import Foundation
8 | import SwiftUI
9 | import Combine
10 |
11 | public struct ToggleFeatureFlag: FeatureFlagType {
12 |
13 | public init(title: String, defaultValue: Bool, group: String? = nil, userDefaults: UserDefaults = .featureFlags) {
14 | self.title = title
15 | self.defaultValue = defaultValue
16 | self.group = group
17 | self.userDefaults = userDefaults
18 | }
19 |
20 | public let title: String
21 | public let defaultValue: Bool
22 | public let group: String?
23 |
24 | private let userDefaults: UserDefaults
25 |
26 | public var value: Bool {
27 | get {
28 | guard
29 | let value = userDefaults.object(forKey: id) as? NSNumber
30 | else {
31 | return defaultValue
32 | }
33 | return value.boolValue
34 | }
35 | nonmutating set {
36 | userDefaults.set(newValue, forKey: id)
37 | }
38 | }
39 |
40 | public var valuePublisher: AnyPublisher {
41 | NotificationCenter.default
42 | .publisher(for: UserDefaults.didChangeNotification)
43 | .map { _ in self.value }
44 | .removeDuplicates()
45 | .eraseToAnyPublisher()
46 | }
47 |
48 | public var view: some View {
49 | Toggle(isOn: valueBinding) {
50 | Text(title)
51 | }
52 | }
53 |
54 | public var isEnabled: Bool {
55 | value
56 | }
57 | }
58 |
59 |
60 | extension FeatureFlagType {
61 | public static func toggle(
62 | title: String, defaultValue: Bool, group: String? = nil, userDefaults: UserDefaults = .featureFlags
63 | ) -> Self where Self == ToggleFeatureFlag {
64 | ToggleFeatureFlag(title: title, defaultValue: defaultValue, group: group, userDefaults: userDefaults)
65 | }
66 | }
67 |
68 | @available(iOS 14, *)
69 | extension FeatureFlag {
70 | public init(
71 | wrappedValue: F.Value, title: String, group: String? = nil, userDefaults: UserDefaults = .featureFlags
72 | ) where F == ToggleFeatureFlag {
73 | self.init(ToggleFeatureFlag(title: title, defaultValue: wrappedValue, group: group, userDefaults: userDefaults))
74 | }
75 | }
76 |
77 |
--------------------------------------------------------------------------------
/Sources/FeatureFlagsController/UI/FeatureFlagViewFactory.swift:
--------------------------------------------------------------------------------
1 | /*
2 | * Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
3 | * This product includes software developed at Datadog (https://www.datadoghq.com/).
4 | * Copyright 2020 Datadog, Inc.
5 | */
6 |
7 | import Foundation
8 | import SwiftUI
9 |
10 | internal struct FeatureFlagViewFactory {
11 |
12 | let id: String
13 | let group: String?
14 | let makeView: () -> AnyView
15 |
16 | init(_ flag: F) {
17 | id = flag.id
18 | group = flag.group
19 | makeView = { AnyView(flag.view) }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Sources/FeatureFlagsController/UI/FeatureFlagsView.swift:
--------------------------------------------------------------------------------
1 | /*
2 | * Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
3 | * This product includes software developed at Datadog (https://www.datadoghq.com/).
4 | * Copyright 2020 Datadog, Inc.
5 | */
6 |
7 | import SwiftUI
8 |
9 | public struct FeatureFlagsView: View {
10 |
11 | public init() {}
12 |
13 | @ObservedObject
14 | private var controller: FeatureFlagsController = .shared
15 |
16 | private var groupedFlags: [(String?, [FeatureFlagViewFactory])] {
17 | var groups: [String?] = []
18 | var map: [String?: [FeatureFlagViewFactory]] = [:]
19 | for factory in controller.viewFactories {
20 | if map.keys.contains(factory.group) == false {
21 | groups.append(factory.group)
22 | }
23 | map[factory.group, default: []].append(factory)
24 | }
25 | return groups.map { ($0, map[$0]!) }
26 | }
27 |
28 | public var body: some View {
29 | NavigationView {
30 | Form {
31 | ForEach(groupedFlags, id: \.0) { groupName, factories in
32 | Section(header: Text(groupName ?? "")) {
33 | ForEach(factories, id: \.id) { factory in
34 | factory.makeView()
35 | }
36 | }
37 | }
38 | }
39 | .navigationBarTitle("Feature Flags")
40 | }
41 | }
42 | }
43 |
44 | struct FeatureFlagsView_Previews: PreviewProvider {
45 | static var previews: some View {
46 | FeatureFlagsView()
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/Tests/FeatureFlagsControllerTests/FeatureFlagsControllerTests.swift:
--------------------------------------------------------------------------------
1 | //
2 | // FeatureFlagsControllerTests.swift
3 | // Datadog
4 | //
5 | // Created by Jérôme Alves on 21/09/2020.
6 | // Copyright © 2020 Datadog. All rights reserved.
7 | //
8 |
9 | import Foundation
10 | import XCTest
11 | import FeatureFlagsController
12 |
13 | class FeatureFlagsControllerTests: XCTestCase {
14 | func testExample() {
15 | // This is an example of a functional test case.
16 | // Use XCTAssert and related functions to verify your tests produce the correct results.
17 | //// XCTAssertEqual(FeatureFlagsController().text, "Hello, World!")
18 | }
19 |
20 | static var allTests = [
21 | ("testExample", testExample),
22 | ]
23 | }
24 |
--------------------------------------------------------------------------------
/Tests/LinuxMain.swift:
--------------------------------------------------------------------------------
1 | import XCTest
2 | @testable import FeatureFlagsControllerTests
3 |
4 | XCTMain([
5 | testCase(FeatureFlagsControllerTests.allTests),
6 | ])
7 |
--------------------------------------------------------------------------------