我无法使快速类符合目标c协议 . 在swift中很容易在目标c协议中实现这些方法,但我无法在以下协议中实现这些属性 .
协议是
@protocol ATLParticipant <NSObject>
@property (nonatomic, readonly) NSString *firstName;
@property (nonatomic, readonly) NSString *lastName;
@property (nonatomic, readonly) NSString *fullName;
@property (nonatomic, readonly) NSString *participantIdentifier;
@end
我已经制作了这个应该符合它的快速类,但是Xcode说它没有 .
class ConversationParticipant: NSObject, ATLParticipant {
var firstName: NSString?
var lastName: NSString?
var fullName: NSString?
var participantIdentifier: NSString?
override init() {
super.init()
}
}
我已经尝试使成员变量可选(如上所述),并解包,并以私有(set)为前缀使它们只读,但这些变体都不起作用 .
3 回答
找到解决方案,在Swift中你不应该使用NSString,而是使用String类型 .
对于ATLParticipant ...
对于ATLAvatarItem ......
我实现了这个解决方案,但仍然出现错误:
“Type'ConversationParticipant'不符合协议'ATLAvatarItem'”
我添加了以下内容来解决它:
工作得很好 .