• Stars
    star
    904
  • Rank 50,534 (Top 1.0 %)
  • Language
    Swift
  • License
    MIT License
  • Created almost 8 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Modify your native iOS app in real time.

Traits - Modify your native iOS app properties in real time.

CircleCI codecov Version License Platform

What are Traits?

Traits allows you to modify the design and behavior of native iOS apps without having to restart them, even across the globe.

Wouldn't it be great if we could adjust designs of our native apps without having to sit back to Xcode, change code, recompile and navigate back to the screen we were at?

Traits is a library that provides you the ability to change many properties of your apps (not only design) without having to recompile the application, even via network across the globe.

Using it offers many benefits:

  • Immediate feedback
  • Ability to update running applications remotely
  • Requires almost no code changes in your app
  • Both Code and Interface Builder designs are supported
  • Can tweak more than just UI
  • Fully tested
  • Supports code injection and real-time programming

Gif

Article describing design and implementation details of this tool

Usage

1. Add the library into your project

2. Assign proper view identifiers either via code:

view.traitSpec = "article.containerView"

or via interface builder:

IBInspectable demo

3. [Optional] If you want live-reloading:

While running on simulator you can observe file on your desktop:

TraitsProvider.setupDesktopDaemon()

While running on device, you can observe remote URL:

TraitsProvider.setupRemoteDaemon(url: myFileURL)

Extending

Traits supports extending the library in real-time, without even having to recompile your project and without unsigning your Xcode 8.

Just install Injection app and code away:
Gif

Adding new Trait that is specific to your project is really simple:

  1. Create a new subclass of Trait
  2. Declares the target types that are supported.
  3. Provide apply function that returns a reversal closure
  4. Declare data mapping using ObjectMapper
  5. Compile. (or code inject as we support that as well)
final public class Constraint: Trait {
    private(set) var constant: CGFloat?

    open override class var restrictedTypes: [AnyClass]? { return [NSLayoutConstraint.self] }

    open override func apply(to target: Trait.Target, remove: inout RemoveClosure) throws {
        let target = target as! NSLayoutConstraint

        remove = { [weak target, constant = target.constant] in
            guard let target = target else { return }
            target.constant = constant
        }

        if let constant = constant {
            target.constant = constant
        }
    }

    public init(constant: CGFloat) {
        super.init()
        self.constant = constant
    }

    public required init?(map: Map) {
        super.init(map: map)
    }

    open override func mapping(map: Map) {
        super.mapping(map: map)
        constant <- map["constant"]
    }
}

Requirements

This library requires a deployment target of iOS 8.0 or greater.

Installation

Traits is available through CocoaPods.

To install it, simply add the following line to your Podfile:

pod "Traits"

Origin

Created by Krzysztof Zabłocki (twitter | website) during Maker Week at The New York Times

Article describing design and implementation details of this tool

Contributing

Contributions to Traits are welcomed and encouraged! Please see the Contributing guide.

A list of contributors is available through GitHub.

To give clarity of what is expected of our members, we adopted the code of conduct defined by the Contributor Covenant. This document is used across many open source communities, and we think it articulates my values well. For more, see the Code of Conduct.

License

Traits is available under the MIT license. See LICENSE for more information.

Attributions

This tool is powered by

Thank you goes to:

  • Véronique Brossier and Chrys Wu from NYT because they helped me clarify expectations for this library.

Other Libraries / Tools

Make sure to check my other libraries and tools, especially:

  • Sourcery - Tool that introduces type-safe meta-programming for swift, allowing you to avoid boilerplate code.
  • KZPlayground - Powerful playgrounds for Swift and Objective-C.
  • KZFileWatchers - Daemon for observing local and remote file changes, used for building other developer tools (Traits uses it)

You can follow me on twitter for news/updates about other projects I am creating.

More Repositories

1

Sourcery

Meta-programming for Swift, stop writing boilerplate code.
Swift
7,677
star
2

LifetimeTracker

Find retain cycles / memory leaks sooner.
Swift
3,144
star
3

Playgrounds

Better playgrounds that work both for Objective-C and Swift
Objective-C
2,633
star
4

Inject

Hot Reloading for Swift applications!
Swift
2,127
star
5

Swift-Macros

A curated list of awesome Swift Macros
Swift
2,120
star
6

Bootstrap

iOS project bootstrap aimed at high quality coding.
Objective-C
2,047
star
7

LineDrawing

Beatiful and fast smooth line drawing algorithm for iOS - as seen in Foldify.
Objective-C
1,288
star
8

Difference

Simple way to identify what is different between 2 instances of any type. Must have for TDD.
Swift
1,217
star
9

PropertyMapper

Property mapping for Objective-C iOS apps.
Objective-C
1,124
star
10

KZFileWatchers

A micro-framework for observing file changes, both local and remote. Helpful in building developer tools.
Swift
1,078
star
11

LinkedConsole

Clickable links in your Xcode console, so you never wonder which class logged the message.
Swift
931
star
12

IconOverlaying

Build informations on top of your app icon.
Shell
650
star
13

crafter

Crafter - Xcode project configuration CLI made easy.
Ruby
547
star
14

Strongify

Strongify is a 1-file µframework providing a nicer API for avoiding weak-strong dance.
Swift
444
star
15

KZNodes

Have you ever wonder how you could make Origami like editor in 1h ?
Objective-C
336
star
16

SFObservers

NSNotificationCenter and KVO auto removal of observers.
Objective-C
307
star
17

AutomaticSettings

Data driven settings UI generation.
Swift
302
star
18

CCNode-SFGestureRecognizers

Adding UIGestureRecognizers to cocos2d, painless.
Objective-C
202
star
19

DetailsMatter

Objective-C
199
star
20

Pinch-to-reveal

Pinch to reveal animation transition built with Layer masking, as seen in boeing app for iPad.
Objective-C
192
star
21

ViewModelOwners

Protocols that help make your MVVM setup more consistent
Swift
143
star
22

KZAsserts

Asserts on roids, test all your assumptions with ease.
Objective-C
100
star
23

OhSnap

Reproduce bugs your user saw by capturing and replaying data snapshots with ease.
Swift
89
star
24

Versionable

Migration for `Codable` objects.
Swift
83
star
25

SFContainerViewController

UIViewControllers containment predating Apple implementation. Works in both 4.x and 5.x iOS, no memory or hierarchy issues.
Objective-C
82
star
26

Swift-Observable

Native KVO like behaviour build in Swift.
Swift
64
star
27

BehavioursExample

Objective-C
58
star
28

SourceryWorkshops

Swift
45
star
29

Learn-iOS-GameDev-Level-0

Teeter clone accompanying tutorial at http://merowing.info/2013/04/learn-ios-game-dev-level-0/
Objective-C
24
star
30

XibReferencing

Simple category and sample showing how you can reference one Xib view from another
Objective-C
20
star
31

KZImageSplitView

Objective-C
17
star
32

NSObject-SFExecuteOnDealloc

A simple category on NSObject that allows you to execute block when object is deallocated
Objective-C
17
star
33

jenkins_jobs_to_statusboard

Ruby script that generates html table for embedding in StatusBoard by Panic http://panic.com/statusboard/
Ruby
15
star
34

SourceryPro-Feedback

Repository for discussing https://merowing.info/sourcery-pro/
12
star
35

krzysztofzablocki

2
star
36

krzysztofzablocki.github.io

Blog
HTML
2
star
37

starter-hugo-academic

Jupyter Notebook
1
star