The CleanroomBridging framework contains utilities that help bridge the gap between Objective-C and Swift.
CleanroomBridging is part of the Cleanroom Project from Gilt Tech.
This is the master
branch. It uses Swift 4.1 and requires Xcode 9.3 to compile.
Branch | Build status |
---|---|
master |
CleanroomBridging is distributed under the MIT license.
CleanroomBridging is provided for your use—free-of-charge—on an as-is basis. We make no guarantees, promises or apologies. Caveat developer.
The simplest way to integrate CleanroomBridging is with the Carthage dependency manager.
First, add this line to your Cartfile
:
github "emaloney/CleanroomBridging" ~> 2.0.0
Then, use the carthage
command to update your dependencies.
Finally, you’ll need to integrate CleanroomBridging into your project in order to use the API it provides.
Once successfully integrated, just add the following statement to any Swift file where you want to use CleanroomBridging:
import CleanroomBridging
See the Integration document for additional details on integrating CleanroomBridging into your project.
The TargetAction
class allows you to use a Swift closure wherever a standard Cocoa target (id
) and action (SEL
) pair can be used.
The closure can take zero or one arguments, as is typical with the target/action paradigm.
You can use a TargetAction
instance to set up UIButton
action handler in conjunction with the addTarget(_:, action:, forControlEvents:)
function declared as part of the UIControl
superclass of UIButton
:
func addActionHandlerForButton(button: UIButton)
{
let handler = TargetAction() { (argument: AnyObject?) -> Void in
let button = argument as? UIButton
println("Button tapped: \(button?.description)")
}
button.addTarget(handler.target, action: handler.action, forControlEvents: .TouchUpInside)
}
The function above sets up a handler that will print out information about button
when it is tapped.
Note that the closure passed to the TargetAction
constructor takes an argument. In the case of a UIControl
target/action, the argument's value will be the control sending the action.
let clock = TargetAction() {
println("The time is now \(NSDate())")
}
let timer = NSTimer.scheduledTimerWithTimeInterval(1.0,
target: clock.target,
selector: clock.action,
userInfo: nil,
repeats: true)
The example above sets up a timer that will result in the current time being printed to the console every second.
For detailed information on using CleanroomBridging, API documentation is available.
The Cleanroom Project began as an experiment to re-imagine Gilt’s iOS codebase in a legacy-free, Swift-based incarnation.
Since then, we’ve expanded the Cleanroom Project to include multi-platform support. Much of our codebase now supports tvOS in addition to iOS, and our lower-level code is usable on macOS and watchOS as well.
Cleanroom Project code serves as the foundation of Gilt on TV, our tvOS app featured by Apple during the launch of the new Apple TV. And as time goes on, we'll be replacing more and more of our existing Objective-C codebase with Cleanroom implementations.
In the meantime, we’ll be tracking the latest releases of Swift & Xcode, and open-sourcing major portions of our codebase along the way.
CleanroomBridging is in active development, and we welcome your contributions.
If you’d like to contribute to this or any other Cleanroom Project repo, please read the contribution guidelines. If you have any questions, please reach out to project owner Paul Lee.
API documentation is generated using Realm’s jazzy project, maintained by JP Simard and Samuel E. Giddins.