protocols

Swift protocol defining class method returning self

橙三吉。 提交于 2019-12-21 14:01:07
问题 I had code that was working in XCode 6 beta but stopped working recently after updating to xcode 6.1. This is my protocol: protocol CanDeserialiseFromJson { class func FromJson(json : JSONValue) -> Self } This is implementation: extension Invoice : CanDeserialiseFromJson { class func FromJson(json : JSONValue) -> Self { return Invoice() } } This fails giving error: 'Invoice' is not convertable to 'Self' As I said, this used to work and I can't work out why it doesn't anymore 回答1: Self in a

Why can't I change variables in a protocol extension where self is a class?

天大地大妈咪最大 提交于 2019-12-21 09:14:19
问题 I am curious why this doesn't work: public protocol MyProtocol { var i: Int { get set } } public protocol MyProtocol2: class, MyProtocol {} public extension MyProtocol2 where Self: AnyObject { func a() { i = 0 <-- error } } Error: Cannot assign to property: 'self' is immutable Why? Only classes can adopt MyProtocol2. If I add : class declaration behind MyProtocol it works. I do not understand why it doesn't work on a subprotocol. 回答1: Your example doesn't compile because MyProtocol isn't

What is the best server client communication protocol to use in Android and iOS?

痴心易碎 提交于 2019-12-21 07:56:22
问题 We have a server application (implemented in Java) that will provide some data for our mobile apps. The apps will be created for Android and iOS. Which is the best protocol / library for this purpose? The overhead of the protocol should be as small as possible. Thanks. Edit: It should be a request->response szenario. Data lost is not acceptable. The answer could contain a long list of data and therfore less overhead is required. The client shall request the data (a specified key and some

Can a category simultaneously implement a protocol?

烂漫一生 提交于 2019-12-21 06:48:23
问题 If a category I'm creating for a class adds methods that also fulfill the contract set out by a protocol, I'd like to flag that category class as implementing the protocol, and thereby indicate to the Obj-C pre-processor that the class effectively implements the protocol as well. Example delegate (for clarity, thanks Ole!): @protocol SomeDelegate <NSObject> - (void)someDelegateMessage; @end Example category: @interface NSObject (SomeCategory) <SomeDelegate> - (void)someDelegateMessage; @end

How secure is authentication in mysql protocol?

我是研究僧i 提交于 2019-12-21 04:08:27
问题 My users are using MS Access and ODBC connector to connect to my remote MySQL database. I wonder how secure this is, in the sense of possible password disclosure to 3rd party. Is the mysql protocol authentication safe to eavesdropping or even man-in-the-middle attacks? I would be quite happy with safety against eavesdropping. Note that my concern is only authentication, I'm not concerned about data disclosure. Please don't reply that I should use SSL. I know this would be ideal however the

Binary communications protocol parser design for serial data

扶醉桌前 提交于 2019-12-20 23:27:02
问题 I'm revisiting a communications protocol parser design for a stream of bytes (serial data, received 1 byte at a time). The packet structure (can't be changed) is: || Start Delimiter (1 byte) | Message ID (1 byte) | Length (1 byte) | Payload (n bytes) | Checksum (1 byte) || In the past I have implemented such systems in a procedural state-machine approach. As each byte of data arrives, the state machine is driven to see where/if the incoming data fits into a valid packet a byte at a time, and

How does Swift memory management work?

女生的网名这么多〃 提交于 2019-12-20 20:00:23
问题 Specifically, how does Swift memory management work with optionals using the delegate pattern? Being accustomed to writing the delegate pattern in Objective-C, my instinct is to make the delegate weak . For example, in Objective-C: @property (weak) id<FooDelegate> delegate; However, doing this in Swift isn't so straight-forward. If we have just a normal looking protocol: protocol FooDelegate { func doStuff() } We cannot declare variables of this type as weak: weak var delegate: FooDelegate?

Class-Only Protocols in Swift

孤街醉人 提交于 2019-12-20 11:03:30
问题 I want some of my classes (not all) to conform using 'Class-Only Protocols' from docs. What I am doing is protocol RefreshData: class, ClassA, ClassB { func updateController() } and I am getting the errors non class type 'RefreshData cannot inherit from classA non class type 'RefreshData cannot inherit from classB I'm not sure I am following exactly as in the docs. Does anyone have any ideas about this? 回答1: Swift 4 allows you to combine types, so you can have your protocol and then create,

Checking whether an object conforms to two separate protocols in Objective-C

会有一股神秘感。 提交于 2019-12-20 10:48:31
问题 In Objective-C when you declare an instance variable you can check if it conforms to a protocol on assignment at compile time like so: id <MyProtocol> variable; Is it possible to check whether an object assigned to the variable conforms to two separate protocols at compile time? As in: id <MyProtocol, MyOtherProtocol> variable; I know I can do runtime checking using conformsToProtocol: and respondsToSelector et al, (which I do before actually using the object for added safety), and I could

Need to satisfy Swift protocol requirement by using a specific subclass of the requirement (or type that conforms to it)

橙三吉。 提交于 2019-12-20 00:21:12
问题 I have a protocol that I've created (in Swift 4.2), and one of its requirements is a property that is of the same type as the protocol itself. As an example, I have a protocol defined like so: protocol A { var a: A? { get set } } I have several Models that conform to this protocol: class Model1: A { var a: A? } class Model2: A { var a: A? } For one of my models, I need to satisfy the protocol requirement by being more specific for the property defined by variable a (i.e. the variable with the