protocols

Where to implement Swift protocols?

落花浮王杯 提交于 2019-12-10 13:27:15
问题 I have two options when implementing protocol conformance in Swift, with the same end result: Implement the protocol within the class - that is, state the conformance at the top of class definition, and put implementation inside the class body, or Implement the protocol in an extension - that is, code up protocol conformance entirely outside the class. Here is an example: public class MyClass : CustomDebugStringConvertible { ... // Something public var debugDescription : String { return

Networking with extremely high latency

本秂侑毒 提交于 2019-12-10 12:52:43
问题 Are there any protocols, systems, etc. experimental or otherwise designed for allowing normal (as normal as can be) network operations (E-mail, DNS, HTML, etc.) over very high latency links? I'm thinking of minutes to an hour, or maybe two. Think light speed lag at a solar system scale. As a side note: research or speculation on the social effects hour to day scale communication delays would be interesting. Current trends tend towards delays of seconds to minutes (plus however long it takes

Expected a type error

倾然丶 夕夏残阳落幕 提交于 2019-12-10 12:38:51
问题 So I created this method: - (void)addToViewController:(SecViewController *)controller didFinishEnteringItem:(NSString *)item;` <br> And Xcode keeps giving me Expected a type error at SecViewController * . What does that mean? SecViewController is not a type? 回答1: You have to declare SecViewController : @class SecViewController; ... at the top of your header. Note: Don't just #import all used headers. This just worsens your header dependencies. 来源: https://stackoverflow.com/questions/10427410

Are stateless protocols considered better to use over stateful protocols?

*爱你&永不变心* 提交于 2019-12-10 12:35:37
问题 I can see that stateful protocols lead to less botched together 'emulated state' like cookies. but testing becomes a lot harder to ensure that your implementation is correct and reconnects, and session continuations can be very hard to handle. Is it considered better practice to always use stateless protocols, or is it really domain specific? I think that authentication becomes easier when dealing with stateful protocols, but are there any other reasons you should use a stateful protocol? 回答1

Designing a file transfer protocol in c++ [closed]

谁说我不能喝 提交于 2019-12-10 11:26:42
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed last year . I need to write a simple file transfer protocol in C++ to upload or download a file from a client to a server. Right now both my client and server applications are do-it-all scripts. I want to modularize everything in classes/methods so I can more easily modify things later. To

Limits of Protocol Extensions and defaults in swift2

隐身守侯 提交于 2019-12-10 09:56:31
问题 So I was playing around with protocol extensions and i ran into an "interesting" problem. I wanted to write a Meters and Kilometers units type for testing some things out. Its VERY easy to do this as a class where there is a base class and both sub classes override the base, while just overriding a simple value //Conversion factor between types enum DISTANCE_UNIT_TYPE : Double { case METER = 1.0; case KILOMETER = 0.001; } protocol DistanceUnit { var unitType : DISTANCE_UNIT_TYPE {get} var

How do I implement a Swift protocol with a generic constrained type property?

时光总嘲笑我的痴心妄想 提交于 2019-12-10 09:45:16
问题 I would like to have a protocol that looks something like this: protocol ReturnType { var returnType: ImmutableMappable.Type { get } } The part of the enum implementing the protocol: extension ShimEndPoint: ReturnType { var returnType: ImmutableMappable.Type { switch self { case .deAuthorize(_, _): return EmptyResponse.self case .authorize(_, _): return AuthorizeResponse.self case .step(_, _, _, _): return StepResponse.self } } } EmptyResponse, AuthorizeResponse and StepResponse all implement

Delegation of singleton class in Swift

泄露秘密 提交于 2019-12-10 06:56:23
问题 How to use delegate methods of singleton/shared class? There is one singleton class having some protocol defined but I'm not getting how to access the delegate functions in other classes. Code snippet for a reference (swift): protocol AClassDelegate { func method1() } class A { static let shared = A() override init() { //initialisation of member variables } var delegate: AClassDelegate func foo() { } } class B: AClassDelegate { func bar() { // Note: not getting call to 'foo' method of class

How to create an object depending on a String in Swift?

三世轮回 提交于 2019-12-10 05:02:23
问题 Here is my code what I would like to refactor: let myCell = MyCustomTableViewCell() self.createCell(myCell, reuseIdentifierString: "myCellIdentifier") the MyCustomTableViewCell conforms to the SetCell protocol so it works fine. and the SetCell protocol is not an @obj_c protocol. This is a swift protocol private func createCell<T where T:SetCell>(classType: T, reuseIdentifierString: String) -> UITableViewCell { var cell = _tableView.dequeueReusableCellWithIdentifier(reuseIdentifierString) as T

Writing a stream protocol: Message size field or Message delimiter?

别等时光非礼了梦想. 提交于 2019-12-10 01:47:44
问题 I am about to write a message protocol going over a TCP stream. The receiver needs to know where the message boundaries are. I can either send 1) fixed length messages, 2) size fields so the receiver knows how big the message is, or 3) a unique message terminator (I guess this can't be used anywhere else in the message). I won't use #1 for efficiency reasons. I like #2 but is it possible for the stream to get out of sync? I don't like idea #3 because it means receiver can't know the size of