Skip to content

Instantly share code, notes, and snippets.

@wh1pch81n
Created March 25, 2017 01:59
Show Gist options
  • Save wh1pch81n/4a91df49610a7ae48a25a07f9f4c1631 to your computer and use it in GitHub Desktop.
Save wh1pch81n/4a91df49610a7ae48a25a07f9f4c1631 to your computer and use it in GitHub Desktop.

Shared code that exists in framework

@objc public protocol Sound {
	@objc optional func woo()
}

public class Foo: NSObject, Sound {
  func action() {
    ((self as Sound).woo ?? default_woo)() // calls `woo` method if available or defaults to default_woo method
  }
  
  func default_woo() {
    // called if class Foo does not implement `woo` somewhere
  }
}

Code that exists in client (aka App Target)

swift

extension Foo {
  func woo() {
    // code code code
  }
}

objc

@implementation Foo (ext)

- (void)woo {
  // code code code
}

@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment