Is it possible to replicate Swifts automatic numeric value bridging to Foundation (NSNumber) for (U)Int8/16/32/64 types?

Yes (it’s possible): by conformance to protocol _ObjectiveCBridgeable (The following answer is based on using Swift 2.2 and XCode 7.3.) Just as I was pondering over whether to post or simply skip this question, I stumbled over swift/stdlib/public/core/BridgeObjectiveC.swift in the Swift source code, specifically the protocol _ObjectiveCBridgeable. I’ve briefly noticed the protocol previously at Swiftdoc.org, … Read more

How do I declare a variable that has a type and implements a protocol?

I think you can get there by adding an (empty) extension to UIViewController and then specifying your detailViewController attribute using a composed protocol of the empty extension and your DetailViewController. Like this: protocol UIViewControllerInject {} extension UIViewController : UIViewControllerInject {} Now all subclasses of UIViewController satisfy protocol UIViewControllerInject. Then with that, simply: typealias DetailViewControllerComposed = … Read more

Swift function object wrapper in apple/swift

I believe these details are mainly part of the implementation of Swift’s IRGen – I don’t think you’ll find any friendly structs in the source showing you the full structure of various Swift function values. Therefore if you want to do some digging into this, I would recommend examining the IR emitted by the compiler. … Read more