Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #51 from agroGandhi/feature/ag/tweak_property_gene…
Browse files Browse the repository at this point in the history
…rator

Tweak Accessor Generator
  • Loading branch information
albertodebortoli authored Apr 27, 2021
2 parents 78946aa + 78dfda3 commit 9b1d747
Show file tree
Hide file tree
Showing 82 changed files with 3,146 additions and 599 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ profile
DerivedData
*.hmap
*.ipa
*.orig

# Bundler
.bundle
Expand All @@ -35,3 +36,4 @@ Carthage/Build
# `pod install` in .travis.yml
#
Pods/
default.profraw
189 changes: 121 additions & 68 deletions Example/JustTweak.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,17 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
codeCoverageEnabled = "YES"
shouldUseLaunchSchemeArgsEnv = "YES">
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "607FACCF1AFB9204008FA782"
BuildableName = "JustTweak_Example.app"
BlueprintName = "JustTweak_Example"
ReferencedContainer = "container:JustTweak.xcodeproj">
</BuildableReference>
</MacroExpansion>
<Testables>
<TestableReference
skipped = "NO">
Expand All @@ -54,17 +63,6 @@
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "607FACCF1AFB9204008FA782"
BuildableName = "JustTweak_Example.app"
BlueprintName = "JustTweak_Example"
ReferencedContainer = "container:JustTweak.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand Down Expand Up @@ -93,8 +91,6 @@
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
3 changes: 3 additions & 0 deletions Example/JustTweak.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"object": {
"pins": [
{
"package": "swift-argument-parser",
"repositoryURL": "[email protected]:apple/swift-argument-parser.git",
"state": {
"branch": null,
"revision": "831ed5e860a70e745bc1337830af4786b2576881",
"version": "0.4.1"
}
}
]
},
"version": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// GeneratedConfigurationAccessor+ExampleProtocol.swift
// Copyright © 2021 Just Eat Takeaway. All rights reserved.
//

import Foundation

extension GeneratedTweakAccessor: ExampleProtocol { }
25 changes: 25 additions & 0 deletions Example/JustTweak/Accessors/GeneratedTweakAccessor+Constants.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// GeneratedTweakAccessor+Constants.swift
// Generated by TweakAccessorGenerator
//

import Foundation

extension GeneratedTweakAccessor {

struct Features {
static let general = "general"
static let uiCustomization = "ui_customization"
}

struct Variables {
static let answerToTheUniverse = "answer_to_the_universe"
static let displayGreenView = "display_green_view"
static let displayRedView = "display_red_view"
static let displayYellowView = "display_yellow_view"
static let greetOnAppDidBecomeActive = "greet_on_app_did_become_active"
static let labelText = "label_text"
static let redViewAlphaComponent = "red_view_alpha_component"
static let tapToChangeColorEnabled = "tap_to_change_color_enabled"
}
}
86 changes: 86 additions & 0 deletions Example/JustTweak/Accessors/GeneratedTweakAccessor.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
//
// GeneratedTweakAccessor.swift
// Generated by TweakAccessorGenerator
//

import Foundation
import JustTweak

class GeneratedTweakAccessor {

static let tweakManager: TweakManager = {
var tweakProviders: [TweakProvider] = []

// EphemeralTweakProvider
#if DEBUG || CONFIGURATION_UI_TESTS
let ephemeralTweakProvider_1 = NSMutableDictionary()
tweakProviders.append(ephemeralTweakProvider_1)
#endif

// UserDefaultsTweakProvider
#if DEBUG || CONFIGURATION_DEBUG
let userDefaultsTweakProvider_1 = UserDefaultsTweakProvider(userDefaults: UserDefaults.standard)
tweakProviders.append(userDefaultsTweakProvider_1)
#endif

// LocalTweakProvider
#if DEBUG
let jsonFileURL_1 = Bundle.main.url(forResource: "LocalTweaks_TopPriority_example", withExtension: "json")!
let localTweakProvider_1 = LocalTweakProvider(jsonURL: jsonFileURL_1)
tweakProviders.append(localTweakProvider_1)
#endif

// LocalTweakProvider
let jsonFileURL_2 = Bundle.main.url(forResource: "LocalTweaks_example", withExtension: "json")!
let localTweakProvider_2 = LocalTweakProvider(jsonURL: jsonFileURL_2)
tweakProviders.append(localTweakProvider_2)

let tweakManager = TweakManager(tweakProviders: tweakProviders)
tweakManager.useCache = true
return tweakManager
}()

var tweakManager: TweakManager {
return Self.tweakManager
}

@TweakProperty(feature: Features.general,
variable: Variables.answerToTheUniverse,
tweakManager: tweakManager)
var meaningOfLife: Int

@TweakProperty(feature: Features.general,
variable: Variables.greetOnAppDidBecomeActive,
tweakManager: tweakManager)
var shouldShowAlert: Bool

@TweakProperty(feature: Features.general,
variable: Variables.tapToChangeColorEnabled,
tweakManager: tweakManager)
var isTapGestureToChangeColorEnabled: Bool

@TweakProperty(feature: Features.uiCustomization,
variable: Variables.displayGreenView,
tweakManager: tweakManager)
var canShowGreenView: Bool

@TweakProperty(feature: Features.uiCustomization,
variable: Variables.displayRedView,
tweakManager: tweakManager)
var canShowRedView: Bool

@TweakProperty(feature: Features.uiCustomization,
variable: Variables.displayYellowView,
tweakManager: tweakManager)
var canShowYellowView: Bool

@TweakProperty(feature: Features.uiCustomization,
variable: Variables.labelText,
tweakManager: tweakManager)
var labelText: String

@TweakProperty(feature: Features.uiCustomization,
variable: Variables.redViewAlphaComponent,
tweakManager: tweakManager)
var redViewAlpha: Double
}
104 changes: 104 additions & 0 deletions Example/JustTweak/Accessors/TweakAccessor.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
//
// TweakAccessor.swift
// Copyright (c) 2016 Just Eat Holding Ltd. All rights reserved.
//

import Foundation
import JustTweak

class TweakAccessor {

static let tweakManager: TweakManager = {
var tweakProviders: [TweakProvider] = []

// UserDefaultsTweakProvider
#if DEBUG || CONFIGURATION_DEBUG
let userDefaultsTweakProvider_1 = UserDefaultsTweakProvider(userDefaults: UserDefaults.standard)
tweakProviders.append(userDefaultsTweakProvider_1)
#endif

// OptimizelyTweakProvider
// let optimizelyTweakProvider = OptimizelyTweakProvider()
// optimizelyTweakProvider.userId = UUID().uuidString
// tweakProviders.append(optimizelyTweakProvider)

// FirebaseTweakProvider
// let firebaseTweakProvider = FirebaseTweakProvider()
// tweakProviders.append(firebaseTweakProvider)

// LocalTweakProvider
#if CONFIGURATION_DEBUG
let jsonFileURL_1 = Bundle.main.url(forResource: "LocalTweaks_TopPriority_example", withExtension: "json")!
let localTweakProvider_1 = LocalTweakProvider(jsonURL: jsonFileURL_1)
tweakProviders.append(localTweakProvider_1)
#endif

// LocalTweakProvider
let jsonFileURL_2 = Bundle.main.url(forResource: "LocalTweaks_example", withExtension: "json")!
let localTweakProvider_2 = LocalTweakProvider(jsonURL: jsonFileURL_2)
tweakProviders.append(localTweakProvider_2)

return TweakManager(tweakProviders: tweakProviders)
}()

private var tweakManager: TweakManager {
return Self.tweakManager
}

// MARK: - Via Property Wrappers

@FallbackTweakProperty(fallbackValue: false,
feature: Features.general,
variable: Variables.greetOnAppDidBecomeActive,
tweakManager: tweakManager)
var shouldShowAlert: Bool

@FallbackTweakProperty(fallbackValue: false,
feature: Features.uiCustomization,
variable: Variables.displayRedView,
tweakManager: tweakManager)
var canShowRedView: Bool

@FallbackTweakProperty(fallbackValue: false,
feature: Features.uiCustomization,
variable: Variables.displayGreenView,
tweakManager: tweakManager)
var canShowGreenView: Bool

@FallbackTweakProperty(fallbackValue: "",
feature: Features.uiCustomization,
variable: Variables.labelText,
tweakManager: tweakManager)
var labelText: String

@FallbackTweakProperty(fallbackValue: 42,
feature: Features.uiCustomization,
variable: Variables.meaningOfLife,
tweakManager: tweakManager)
var meaningOfLife: Int

@OptionalTweakProperty(fallbackValue: nil,
feature: Features.uiCustomization,
variable: Variables.answerToTheUniverse,
tweakManager: tweakManager)
var optionalMeaningOfLife: Int?


// MARK: - Via TweakManager

var canShowYellowView: Bool {
return tweakManager.tweakWith(feature: Features.uiCustomization,
variable: Variables.displayYellowView)?.boolValue ?? false
}

var redViewAlpha: Float {
return tweakManager.tweakWith(feature: Features.uiCustomization,
variable: Variables.redViewAlpha)?.floatValue ?? 0.0
}

var isTapGestureToChangeColorEnabled: Bool {
return tweakManager.tweakWith(feature: Features.general,
variable: Variables.tapToChangeViewColor)?.boolValue ?? false
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ import UIKit
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?
let configurationAccessor = ConfigurationAccessor()
let tweakAccessor = GeneratedTweakAccessor()

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
let navigationController = window?.rootViewController as! UINavigationController
let viewController = navigationController.topViewController as! ViewController
viewController.configurationAccessor = configurationAccessor
viewController.tweakManager = ConfigurationAccessor.tweakManager
viewController.tweakAccessor = tweakAccessor
viewController.tweakManager = TweakAccessor.tweakManager
return true
}

func applicationDidBecomeActive(_ application: UIApplication) {
if configurationAccessor.shouldShowAlert {
if tweakAccessor.shouldShowAlert {
let alertController = UIAlertController(title: "Hello",
message: "Welcome to this Demo app!",
preferredStyle: .alert)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ViewController: UIViewController {
@IBOutlet var yellowView: UIView!
@IBOutlet var mainLabel: UILabel!

var configurationAccessor: ConfigurationAccessor!
var tweakAccessor: GeneratedTweakAccessor!
var tweakManager: TweakManager!

private var tapGestureRecognizer: UITapGestureRecognizer!
Expand All @@ -36,25 +36,25 @@ class ViewController: UIViewController {

internal func updateView() {
setUpGestures()
redView.isHidden = !configurationAccessor.canShowRedView
greenView.isHidden = !configurationAccessor.canShowGreenView
yellowView.isHidden = !configurationAccessor.canShowYellowView
mainLabel.text = configurationAccessor.labelText
redView.alpha = CGFloat(configurationAccessor.redViewAlpha)
redView.isHidden = !tweakAccessor.canShowRedView
greenView.isHidden = !tweakAccessor.canShowGreenView
yellowView.isHidden = !tweakAccessor.canShowYellowView
mainLabel.text = tweakAccessor.labelText
redView.alpha = CGFloat(tweakAccessor.redViewAlpha)
}

internal func setUpGestures() {
if tapGestureRecognizer == nil {
tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(changeViewColor))
view.addGestureRecognizer(tapGestureRecognizer)
}
tapGestureRecognizer.isEnabled = configurationAccessor.isTapGestureToChangeColorEnabled
tapGestureRecognizer.isEnabled = tweakAccessor.isTapGestureToChangeColorEnabled
}

@objc internal func setAndShowMeaningOfLife() {
configurationAccessor.meaningOfLife = Bool.random() ? 42 : nil
tweakAccessor.meaningOfLife = Bool.random() ? 42 : 108
let alertController = UIAlertController(title: "The Meaning of Life",
message: String(describing: configurationAccessor.meaningOfLife),
message: String(describing: tweakAccessor.meaningOfLife),
preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
present(alertController, animated: true, completion: nil)
Expand Down
Loading

0 comments on commit 9b1d747

Please sign in to comment.