I'm trying to to conform to this protocol in swift
Protocol
@protocol XLFormOptionObject <NSObject>
@required
-(NSString *)formDisplayText;
-(id)formValue;
@end
My Class which should conform to this protocol
@objc (myclass)
class myclass : XLFormOptionObject{
var formDisplayText: NSString {
return self.name
}
var formValue: AnyObject {
return self
}
}
Comment
As per my understand i should change id with Anyobject, but the XCode 6.1 is still give me compiler error - Class dose not conform to protocol
Question
Any suggestions how to conform to protocol with A pointer to an instance of a class "id"
Your issue isn't the
formValue()
func, but rather theformDisplayText()
func. You must force unwrap the string. It's not clear to me why this is required since the return value is clearly not an optional, but if you look at how swift converts objc method calls for bridging you'll notice that it will almost always reinterpret method return values as forced unwrapped.