David
David

Reputation: 7456

How am I not following this protocol?

Is there something I don't understand?

Protocol:

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()
}

My code:

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...
}

The error I keep getting: "Type 'TypingListView' does not conform to protocol 'SLKTypingIndicatorProtocol'"

When I expand the error it states: "Protocol requires property 'visible' with type 'Bool'". It also says "Objective-C method 'visible' provided by getter for 'visible' does not match the requirement's selector ('isVisible')"

I found how the protocol actually reads in Objective-C as well:

#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

Upvotes: 3

Views: 115

Answers (1)

beeth0ven
beeth0ven

Reputation: 1882

Tips, try this style:

public var visible: Bool {
    @objc(isVisible) get {
        return self._visible
    }

    set (val) {
        self._visible = val
    }
}

Upvotes: 2

Related Questions