protocols

extend a protocol privately using a category in objective c

。_饼干妹妹 提交于 2019-12-10 21:27:34
问题 did some searching and didn't find much, but wondering if it's possible to extend a protocol. Currently, in MyDelegate.h, there is: @protocol MyDelegate <NSObject> hoping to create a private header, MyDelegate+Private.h, to not expose extra optional methods to the client. @protocol MyDelegate (Private) <NSObject> this doesn't seem to work. is it possible? would like to avoid creating a whole new delegate protocol that holds a superset of the current one. 回答1: I don't think you can create a

Assigning an array of structs to an array of protocols

被刻印的时光 ゝ 提交于 2019-12-10 18:54:46
问题 Let's say I have the following: protocol MyProtocol { } struct MyStruct: MyProtocol { } var s1 = MyStruct() var s2 = MyStruct() var s3 = MyStruct() var structArray = [s1, s2, s3] When I try to assign this array of structs to an array of protocols (that each struct in structArray conforms to): var protocolArray:[MyProtocol] = structArray I get this error: Cannot convert array of type '[MyStruct]' to specified type '[MyProtocol]' I would expect that since each object in the array conforms to

if Delegate sends gesture messages do they conform to my customised Objective C protocol?

笑着哭i 提交于 2019-12-10 17:54:00
问题 I am trying to send gesture messages from several subclassed UIViews to common handlers in a UIViewController called TouchController. I am using a customised protocol to address a question arising from the answer to my previous SO post. Messages are now sent from OneOfSeveralSubviews using a customised protocol called FirstGestureRecognizerDelegate but none of the handlers respond even though the code compiles with 0 warnings. I am confident the problem is not in TouchController for reasons

Integration Objective C Protocols with Swift

最后都变了- 提交于 2019-12-10 17:08:20
问题 I am new in swift and i need some help to integrate a component AKPickerView (written in Objective C). link of component: https://github.com/Akkyie/AKPickerView But i have no success, because there is a protocol: AKPickerViewDelegate that don't work in Swift: @class AKPickerView; @protocol AKPickerViewDelegate <NSObject> @optional - (NSString *)pickerView:(AKPickerView *)pickerView titleForItem:(NSInteger)item; - (NSUInteger)numberOfItemsInPickerView:(AKPickerView *)pickerView; - (void

Why delegate methods needs to be public in Swift?

限于喜欢 提交于 2019-12-10 16:35:34
问题 I am working on a framework in swift. I am creating a class which deals with BLE stuff in the framework. This class should be public as I need to access this class from external application which uses my framework. My class structure is a below: public class MyClass: NSObject, CBCentralManagerDelegate { } Here MyClass is public, which confirms a public protocol CBCentralManagerDelegate . Compiler force me to declare it's delegate methods as public. So here is what my implementation looks like

Client does not support authentication protocol requested by server

吃可爱长大的小学妹 提交于 2019-12-10 16:16:03
问题 I need to establish PHP4 environment in conjunction with mysql5 and I am facing this problem when I try to connect to mysql. Thank you for any trace. 回答1: The solution is to update the database user’s password using the OLD_PASSWORD function of MySQL. For example: [chris@office ~]$ mysql -u root -p mysql Enter password: Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Welcome to the MySQL monitor. Commands end

Swift: binary operator '==' cannot be applied to operands of type “protocol”

可紊 提交于 2019-12-10 15:27:18
问题 I have a protocol: protocol ProfileManagerDelegete { func dataHaveUpdated(type: ReturnType) } and create a protocol array, and add/remove listener: var listeners: [ProfileManagerDelegete] = [] func addListener(listener: ProfileManagerDelegete) { listeners.append(listener) } func removeLister(listener: ProfileManagerDelegete) { for lis in listeners { if lis == listener { // this line error //remove listener } } } Anyone can help ? 回答1: Because you have not told Swift how to compare 2 objects

Iterate array of weak references where objects conform to a protocol in Swift

那年仲夏 提交于 2019-12-10 15:16:37
问题 I want to store objects in an array, where objects are weak, and conforms to a protocol. But when I try to loop it, I get a compiler error: public class Weak<T: AnyObject> { public weak var value : T? public init (value: T) { self.value = value } } public protocol ClassWithReloadFRC: class { func reloadFRC() } public var objectWithReloadFRC = [Weak<ClassWithReloadFRC>]() for owrfrc in objectWithReloadFRC { //If I comment this line here, it will able to compile. //if not I get error see below

Why does “conformsToProtocol” not check for “required” method implementations?

非 Y 不嫁゛ 提交于 2019-12-10 14:49:27
问题 I am trying to enforce a "formal" @protocol , but cannot reliably test my classes/instances as to whether they ACTUALLY implement the protocol's "required" methods, vs. simply "declaring" that they conform to the protocol. A complete example of my quandary… #import <Foundation/Foundation.h> @protocol RequiredProtocol @required - (NSString*) mustImplement; @end @interface Cog : NSObject <RequiredProtocol> @end @implementation Cog @end @interface Sprocket : NSObject @end @implementation

Is there a way to create a type alias in protobuf (proto2)?

北城余情 提交于 2019-12-10 13:42:10
问题 Is it possible to create aliases of protobuf's scalar types? For example, I'd like to use Sequence in lieu of string , even though they would be binary equivalent. My immediate goal is to make documentation (generated with protoc-gen-doc) more readily understandable. Ideally, this type would be represented in languages that support type checking, but that's not necessary. 回答1: Well this will be a bit dull answer but: No, I'm not aware of such feature existing or having been planned. You can