【发布时间】:2016-08-07 07:45:35
【问题描述】:
有什么我不明白的地方吗?
协议:
public protocol SLKTypingIndicatorProtocol : NSObjectProtocol {
/**
Returns YES if the indicator is visible.
SLKTextViewController depends on this property internally, by observing its value changes to update the typing indicator view's constraints automatically.
You can simply @synthesize this property to make it KVO compliant, or override its setter method and wrap its implementation with -willChangeValueForKey: and -didChangeValueForKey: methods, for more complex KVO compliance.
*/
public var visible: Bool { get set }
/**
Dismisses the indicator view.
*/
optional public func dismissIndicator()
}
我的代码:
public class TypingListView: UIView, SLKTypingIndicatorProtocol {
var _visible: Bool = false
public var visible: Bool {
get {
return self._visible
}
set (val) {
self._visible = val
}
}
public func isVisible() -> Bool {
return self.visible
}
public func dismissIndicator() {
self.visible = false
}
// Other code...
}
我不断收到的错误:“类型'TypingListView'不符合协议'SLKTypingIndicatorProtocol'”
当我展开错误时,它指出:“协议需要具有类型 'Bool' 的属性 'visible'”。它还说“getter for 'visible' 提供的 Objective-C 方法 'visible' 与需求的选择器 ('isVisible') 不匹配”
我还发现了协议在 Objective-C 中的实际读取方式:
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/** Generic protocol needed when customizing your own typing indicator view. */
@protocol SLKTypingIndicatorProtocol <NSObject>
@required
/**
Returns YES if the indicator is visible.
SLKTextViewController depends on this property internally, by observing its value changes to update the typing indicator view's constraints automatically.
You can simply @synthesize this property to make it KVO compliant, or override its setter method and wrap its implementation with -willChangeValueForKey: and -didChangeValueForKey: methods, for more complex KVO compliance.
*/
@property (nonatomic, getter = isVisible) BOOL visible;
@optional
/**
Dismisses the indicator view.
*/
- (void)dismissIndicator;
@end
NS_ASSUME_NONNULL_END
【问题讨论】:
标签: objective-c swift xcode