Last active
January 15, 2018 10:36
-
-
Save yunarta/dca6b721333897645cccf9c94a6f1513 to your computer and use it in GitHub Desktop.
Generic and optional obj-c method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
@objc protocol One: NSObjectProtocol { | |
@objc optional func method() | |
} | |
class NoGenericBase: NSObject, One { } | |
class NoGenericImpl: NoGenericBase { | |
func method() { print("second method") } | |
} | |
var noGeneric = NoGenericImpl() | |
if noGeneric.responds(to: #selector(One.method)) { | |
print("no generic comform One.method") | |
} else { | |
print("no generic NOT comforming One.method") | |
} | |
class GenericBase<Base>: NSObject, One { } | |
class GenericImpl: GenericBase<String> { | |
func method() { print("second method") } | |
} | |
var generic = GenericImpl() | |
if generic.responds(to: #selector(One.method)) { | |
print("generic comform One.method") | |
} else { | |
print("generic NOT comform One.method") | |
} | |
class ObjcGenericImpl: GenericBase<String> { | |
@objc func method() { print("second method") } | |
} | |
var genericObjc = ObjcGenericImpl() | |
if genericObjc.responds(to: #selector(One.method)) { | |
print("generic+@objc comform One.method") | |
} else { | |
print("generic+@objc NOT comform One.method") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
no generic comform One.method | |
generic NOT comform One.method | |
generic+@objc comform One.method |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment