Swiftpack.co - mediamonks/MMMTweaks as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by mediamonks.
mediamonks/MMMTweaks 2.2.1
Swift support for Facebook's Tweaks library
⭐️ 3
🕓 31 weeks ago
iOS
.package(url: "https://github.com/mediamonks/MMMTweaks.git", from: "2.2.1")

MMMTweaks

Build

Swift support for Facebook's Tweaks library.

(This is a part of MMMTemple suite of iOS libraries we use at MediaMonks.)

Quick example

We're trying to keep the spirit of super convenience Tweak's ObjC macros.

import MMMTweaks

// On startup:
#if DEBUG // Or any other condition when you want to have Tweaks enabled.
MMMTweaks.register()
#endif

// Anywhere in your code, but better closer to the use site:
extension MMMTweaks {
    @objc static var shouldMockCookies: BoolTweak = {
        return BoolTweak(path: .init("Test", "Mocks", "Mock cookies"), defaultValue: false)
    }()
}

// Use site:
if MMMTweaks.shouldMockCookies.isOn {
    // ...
}

Both the original Tweaks library and this Swift shim are by default enabled whenever DEBUG macro and DEBUG Swift active compilation conditions are correspondinly defined in their targets.

To enable both libraries in configs where DEBUG is not defined you would need to define FB_TWEAK_ENABLED macro as 1 for Tweaks and add FB_TWEAK_ENABLED active compilation condition for MMMTweaks.

For example, you can enable both libs for non-Debug configs of your choice via a postinstall script in your Podfile:

post_install do |installer|
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
            if (target.name == "MMMTweaks" || target.name == "Tweaks") && (config.name == "<YourSpecialConfig>")
                config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']
                config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'FB_TWEAK_ENABLED=1'
                config.build_settings['SWIFT_ACTIVE_COMPILATION_CONDITIONS'] ||= ['$(inherited)']
                config.build_settings['SWIFT_ACTIVE_COMPILATION_CONDITIONS'] << 'FB_TWEAK_ENABLED'
            end
        end
    end
end

Installation

Podfile:

source 'https://github.com/mediamonks/MMMSpecs.git'
source 'https://github.com/CocoaPods/Specs.git'
...
pod 'MMMTweaks'

SPM:

.package(url: "https://github.com/mediamonks/MMMTweaks", .upToNextMajor(from: "2.2.0"))

Ready for liftoff? 🚀

We're always looking for talent. Join one of the fastest-growing rocket ships in the business. Head over to our careers page for more info!

GitHub

link
Stars: 3
Last commit: 31 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

2.2.1
31 weeks ago

Commits

  • 9dae24e: Update README.md (Erik Terwan)
  • 6829055: Add autorelease action (Erik Terwan)
  • 3750e21: Add auto-document workflow (Erik Terwan)
  • 003ac62: Fix a small mem leak happening during registration (Aleh Dzenisiuk)

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics