车家互联 小程序在智能汽车时代的创新与发展潜力
532
2022-10-23
实时修改您原生iOS应用程序的属性
Traits - Modify your native iOS app properties in real time.
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 feedbackAbility to update running applications remotelyRequires almost no code changes in your appBoth Code and Interface Builder designs are supportedCan tweak more than just UIFully testedSupports code injection and real-time programming
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:
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.
Adding new Trait that is specific to your project is really simple:
Create a new subclass of TraitDeclares the target types that are supported.Provide apply function that returns a reversal closureDeclare data mapping using ObjectMapperCompile. (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
Object Mapper
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.
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~