Swiftpack.co - tokopedia/ios-tptweak as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by tokopedia.
tokopedia/ios-tptweak 1.0.0
Debugging tool to help adjust your iOS app on the fly without recompiling
⭐️ 22
🕓 3 weeks ago
iOS
.package(url: "https://github.com/tokopedia/ios-tptweak.git", from: "1.0.0")

TPTweak

TPTweak is a debugging tool to help adjust your iOS app on the fly without recompile. inspired by facebook's Tweak, TPTweak is fully written in swift, and with simpler API.

Example of TPTweak Selecting options of string Selecting options of number

Installation

Swift Package Manager

With xcode, add this URL

https://github.com/tokopedia/ios-tptweak

or manually add to your Package.swift

.package(url: "https://github.com/tokopedia/ios-tptweak", from: "1.0.0"),

Cocoapods

add this to your Podfile

pod 'TPTweak', '~> 1.0.0'

Nomenclature

TPTweakEntry = Representation of option on TPTweak

TPTweakStore = Brain of TPTweak, all logic of storing, reading and mutating value of TPTweak.

TPTweakEntry

TPTweakEntry will represent a option on TPTweak.

TPTweakEntry(
    category: "Tracking",
    section: "Tracking",
    cell: "Enable Tracking",
    footer: "Turn this on to enable tracking",
    type: .switch(defaultValue: true)
)
  • category: will be a cell on the first page
  • section: will be a group of section on the second page
  • cell: will be the name of the cell inside the section
  • footer: add footer on the end of the section.(if multiply detected, will use the last one)
  • type: the type of cell you want to use

TPTweakEntry type

Switch

Using this type, you can create a cell with a UISwitch to enable/disable an option.You could also supply default value, if no value detected.

.switch(defaultValue: true)

Strings

Using this type, you can create a selection of strings.When user tap the options, it will automatically open the selection.

.strings(item: ["US", "UK", "SG"], selected: "SG")

Numbers

Using this type, you can create a selectio of numbers.When user tap the options, it will automatically open the selection.

.numbers(item: [10, 15, 20], selected: 10)

Action

Using this type, it gives you the flexibility to do everything. with given closure, you can for example, open custom page you create, or executing a UserDefaults, or more.

.action({
    UserDefaults.standard.set(true, forKey: "clear_cache")
    Cache.clear()
})

How to Use

Creating your TPTweakEntry

first you need to create your entry, we recommend to create an extension and put every entry definition as a static.

import TPTweak

extension TPTweakEntry {
    static let enableTracking = TPTweakEntry(
        category: "Tracking",
        section: "Tracking",
        cell: "Enable Tracking",
        footer: "Turn this on to enable tracking",
        type: .switch(defaultValue: true)
    )
}

Registering your TPTweakEntry

once you create your entry, you need to register it to TPTweak so it will show up on TPTweak page. This can be achieved by calling register() on each entry.

You can call it whenever you want, but we suggest to put it on your AppDelegate's internal func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?)

internal func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // register TPTweak Entry
        TPTweakEntry.enableTracking.register()
    }

Openning TPTweak page

openning TPTweak is achievable by openning TPTweakViewController. but the easier way is to replace your UIWindow with TPTweakShakeWindow.

Manual

// without nav
let viewController = TPTweakViewController()
self.navigationController?.pushViewController(viewController, animated: true)

// with nav
let tptweakWithNav = TPTweakWithNavigatationViewController()
self.present(tptweakWithNav)

Shake (Recommended)

@UIApplicationMain
internal final class AppDelegate: UIResponder, UIApplicationDelegate {
    internal var window: UIWindow?

    internal func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // register TPTweakShakeWindow to enable openning TPTweak from shaking the device
        window = TPTweakShakeWindow(frame: UIScreen.main.bounds)
        ...
    }
}

Use TPTweak Value

Once your TPTweakEntry is set, you can get and set a value from it.

Read value

// will return true or false based on latest value changed on TPTweak
let isTrackingEnable = TPTweakEntry.enableTracking.getValue(Bool.self) 

Set value

if you want to set the value manually programmatically

TPTweakEntry.enableTracking.setValue(true)

License

 Copyright 2022 Tokopedia. All rights reserved.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.

GitHub

link
Stars: 22
Last commit: 3 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

1.0.0
3 weeks ago

Initial Release

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