Swift — Require classes implementing protocol to be subclasses of a certain class

Update. In the latest Swift version you can just write protocol TransmogrifiableView: NSView { func transmogrify() } , and this will enforce the conformer types to be either NSView, or a subclass of it. This means the compiler will “see” all members of NSView. Original answer There is a workaround by using associated types to … Read more

How to map a custom protocol to an application on the Mac?

I’ve not had occasion to use it, but some time ago I bookmarked OS X URL handler to open links to local files which is exactly what you’re looking for. The important part of the linked procedure is adding an appropriate CFBundleURLTypes to your application’s Info.plist that describes the scheme. The example given there looks … Read more

Swift Protocol get only settable?

Apple states in the “Swift Programming Languages Documentation”: If the protocol only requires a property to be gettable, the requirement can be satisfied by any kind of property, and it is valid for the property to be also settable if this is useful for your own code. For this reason, the five following Playground code … 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