Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 259
David Avatar asked Jan 29 '26 15:01

David


1 Answers

Tips, try this style:

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

    set (val) {
        self._visible = val
    }
}
like image 180
beeth0ven Avatar answered Jan 31 '26 05:01

beeth0ven



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!