[Tip] Swift -> Protocol Conditional Extension

protocol MyProtocol {

}

extension MyProtocol where Self: ImmutableMappable {
static func createObject() -> [Self]  {
var items = [Self]()
var json: [String: Any] = [“greeting”: “hello world”]
let item = self.init(JSON: json)
items.append(item)

return items
}

}

 

https://stackoverflow.com/questions/35133887/how-to-require-that-a-protocol-can-only-be-adopted-by-a-specific-class

[ios] NSObject respondsToSelector

http://stackoverflow.com/questions/3697058/when-to-use-respondstoselector-in-objective-c

1. 오래된 프레임워크 호환성을 위해 사용

if ([someObject responsToselector:@selector(newApiMethod)]) {
// ios 8
[someObject newAPiMethod];
} else {
// ios 6
[someObject oldAPiMethod];
}

2. Protocol Delegate의 optional로 지정된 메서드를 호출할 때 사용.