Upgrade to Pro — share decks privately, control downloads, hide ads and more …

SwiftTweaks

 SwiftTweaks

関西モバイルアプリ研究会 #14での発表資料です #関モバ

http://kanmoba.connpass.com/event/31750/

Sho Ikeda

May 25, 2016
Tweet

More Decks by Sho Ikeda

Other Decks in Programming

Transcript

  1. Why? • Parameters adjustment • Animation (location, duration, ...) •

    Color • Layout • ... • Debug mode • Clear settings • Change API environment • Toggle experimental features • ... • And what you want
  2. Objective-C // Value CGFloat animationDuration = FBTweakValue(@"Category", @"Group", @"Duration", 0.5);

    // Bind FBTweakBind(self.headerView, alpha, @"Main Screen", @"Header", @"Alpha", 0.85); FBTweakBind(webView.scrollView, scrollEnabled, @"Browser", @"Scrolling", @"Enabled", YES); // Action FBTweakAction(@"Player", @"Audio", @"Volume", ^{ NSLog(@"Action selected."); });
  3. Swift // FBTweak~~ are macro, so those can't be used

    in Swift let tweak = FBTweak(identifier: "com.tweaks.example.advanced") tweak.name = "Advanced settings" tweak.defaultValue = false let collection = FBTweakCollection(name: "Enable"); collection.addTweak(tweak) let category = FBTweakCategory(name: "Settings") category.addTweakCollection(collection) let store = FBTweakStore.sharedInstance() store.addTweakCategory(category) tweak.addObserver(self) func tweakDidChange(tweak: FBTweak!) { self.advancedSettingsEnabled = tweak.currentValue as Bool }
  4. !!!

  5. SwiftTweaks Tweak your iOS app without recompiling! • Supported types

    • Bool • Int • CGFloat • Double • UIColor • Group template • Floating window
  6. Steps 1. Create a TweakLibraryType. 2. Reference that TweakLibraryType in

    your code to use a Tweak. 3. Use the TweakWindow in your AppDelegate.
  7. Make your TweakLibrary public struct ExampleTweaks: TweakLibraryType { public static

    let colorTint = Tweak( "General", "Colors", "Tint", UIColor.blueColor()) public static let marginHorizontal = Tweak<CGFloat>( "General", "Layout", "H. Margins", defaultValue: 15, min: 0) public static let marginVertical = Tweak<CGFloat>( "General", "Layout", "V. Margins", defaultValue: 10, min: 0) public static let featureFlagMainScreenHelperText = Tweak( "Feature Flags", "Main Screen", "Show Body Text", true) public static let buttonAnimation = SpringAnimationTweakTemplate( "Animation", "Button Animation") ... }
  8. Make your TweakLibrary public struct ExampleTweaks: TweakLibraryType { ... public

    static let defaultStore: TweakStore = { let allTweaks: [TweakClusterType] = [colorTint, marginHorizontal, marginVertical, featureFlagMainScreenHelperText, buttonAnimation ] #if DEBUG let tweaksEnabled: Bool = true #else let tweaksEnabled: Bool = false #endif return TweakStore( tweaks: allTweaks, enabled: tweaksEnabled ) }() }
  9. Using Your TweakLibrary // Assign button.tintColor = ExampleTweaks.assign(ExampleTweaks.colorTint) // Bind

    ExampleTweaks.bind(ExampleTweaks.colorTint) { button.tintColor = $0 } // Bind multiple let tweaksToWatch: [TweakType] = [ ExampleTweaks.marginHorizontal, ExampleTweaks.marginVertical ] ExampleTweaks.bindMultiple(tweaksToWatch) { let horizontal = ExampleTweaks.assign(ExampleTweaks.marginHorizontal) let vertical = ExampleTweaks.assign(ExampleTweaks.marginVertical) scrollView.contentInset = UIEdgeInsets( top: vertical, right: horizontal, bottom: vertical, left: horizontal) }
  10. Roadmaps Let's contribute! ✨ • "Backups" feature • Support String

    as a TweakViewDataType • Add a "closure" Tweak Type • Design & Build tvOS UI • Design & Build iPad UI