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.0
Swift support for Facebook's Tweaks library
⭐️ 2
🕓 8 weeks ago
iOS
.package(url: "https://github.com/mediamonks/MMMTweaks.git", from: "2.2.0")

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: 2
Last commit: 2 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

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