Skip to content
This repository was archived by the owner on Nov 2, 2020. It is now read-only.
This repository was archived by the owner on Nov 2, 2020. It is now read-only.

Swiftish syntax? #98

Open
Open

Description

@lexrus
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;
}

Compared to:

FBTweakStore.sharedInstance()
  + FBTweakCategory(name: "Settings")
  + FBTweakCollection(name: "Enabled")
  + FBTweak<Bool>("com.fb.example", "Advanced settings", false) {
      tweak in
      self.advancedSettingsEnabled = tweak.currentValue
    }

And the rhs should support Array as well:

let collection = FBTweakCollection(name: "Enabled")
    + [
        FBTweak<Bool>("com.fb.example", "Advanced settings", false) {
          tweak in
          self.advancedSettingsEnabled = tweak.currentValue
        },
        // Another Tweak
      ]

Activity

  1. grp commented on Dec 24, 2015

    @grp
    Contributor

    I like that syntax!

    The main barrier to Tweaks in Swift is that they aren't loaded at load time — the code has to run to initialize the tweak. Without a workaround for that, it's hard to make it nearly as practical as in Objective-C, since you'll often end up with duplicate tweaks (if you create them within an object) or a lot of boilerplate code to store static instances of them.

    I haven't come up with a good way to work around that, but I'm still looking. If one is found, I think that will be a good impetus to make the rest of Tweaks work well in Swift too.

  2. dulacp commented on Jan 26, 2016

    @dulacp

    Some time ago I came up with this implement for a Swift tweak syntax.

    Still there is the fact that it needs to run to be loaded, but it doesn't result in duplicates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions