protocols

Calling method in another view controller from modal view controller using a delegate

末鹿安然 提交于 2019-12-24 18:49:21
问题 I am using a modal segue to create a view controller that I want to dismiss and then call a method in the origin view controller. I have used a protocol/delegate pattern but for some reason the method is never called. The code is below: Please note that I removed a lot of non-relevant code to keep it clean here Thanks!! VC1: final class WorkoutViewController: UIViewController, StartWorkoutButtonDelegate { weak var dataSource: WorkoutViewControllerDataSource! private var workout: Workout!

Go Back N Vs. Selective Repeat

狂风中的少年 提交于 2019-12-24 18:15:01
问题 Are there any reasons why Go Back N would be preferred over selective repeat for pipelined error recovery ? Clearly, SR needs a buffer (appropriately sized) at the receiver's end, is that its only weakness ? Any situation where GBN would be exclusively preffered? 回答1: My answer might not be too relevant to your question, but it focuses on receive buffer problem of Selective Repeat. Selective Repeat is much more smart and efficient way of dealing with unreliability of UDP. But only if it's

Public default init in protocol

半腔热情 提交于 2019-12-24 17:18:13
问题 I have this code: public protocol MyProtocol { init() } public extension MyProtocol { public init() { self.init() } } public final class MyClass: MyProtocol {} I got an error saying: Initializer 'init()' must be declared public because it matches a requirement in public protocol 'MyProtocol' If I remove the access control ( public ) before final , it works. But why? Is there any way I can let the protocol handle the init? I thought all members of protocols are implicitly public by default.

Generating packets

百般思念 提交于 2019-12-24 15:25:45
问题 I want to know how to generate a packet in c. Supposed we have a type as follows: struct ipheader { int version; int hdLen; int tos; int totLen; int id; ...... int dstIp; } And we have a ipheader type: struct ipheader ip; //init the ip ..... How can I generate a packet(just ip header part) from "ip". Could anyone show me how? I want to know to generate packets with information such as mac address, ip header, tcp header, payload. Then I can use the "pcap_sendpacket" function to send the

How to use protocol

做~自己de王妃 提交于 2019-12-24 14:00:01
问题 I have two viewControllers ServiceProvider WorkLocation In ServiceProvider I have one text field and a pick button. When user click on pick button it will redirect to WorkLocation which has a list of location s. When user select any location and then click on pick button from WorkLocation it will redirect back to ServiceProvider page with locationName and Id . And in ServiceProvider page locationName will be displayed in the text field which is already there. To perform this I am using a

Segfault when Associated Type conforms to a protocol

可紊 提交于 2019-12-24 13:16:16
问题 I have a problem with Swift compiler segfaulting when trying to compile the code below. I've already posted a bug report on this, but wonder if: 1) I'm doing anything inherently wrong 2) there is a 'workaround' I could use to achieve a similar result. I suppose not, but I'd appreciate any ideas you might have class Foo<T, U: AnyObject> { } protocol Bar { typealias T: AnyObject // <- that appears to be the problem func foo() -> Foo<Self, T> } extension String: Bar { func foo() -> Foo<String,

Need clarification on “@objc class” in Swift

流过昼夜 提交于 2019-12-24 11:36:40
问题 I understand what the "@objc" attribute does for protocols. What I don't understand is why it is added to classes, such as in the following example: @objc protocol CounterDataSource { optional func incrementForCount(count: Int) -> Int optional var fixedIncrement: Int { get } } @objc class Counter { var count = 0 var dataSource: CounterDataSource? func increment() { if let amount = dataSource?.incrementForCount?(count) { count += amount } else if let amount = dataSource?.fixedIncrement { count

How to know when you finish receiving a TCP stream?

亡梦爱人 提交于 2019-12-24 08:56:39
问题 I'm not sure how to tell in TCP when the sender finished sending me the information. For example if A needs to send 200 bytes to B, how will B know that A finished sending, and that the information is ready to be transferred to the application layer? There's the FIN flag, but as far as I know it's only there to symbolizes that your going to close the connection. Thanks. 回答1: TCP has no obligation to tell the receiver when the sender has finished sending data on the connection. It can't

Client/server - How to separate protocol from network logic?

自闭症网瘾萝莉.ら 提交于 2019-12-24 08:48:16
问题 I want to implement and unit test (not necessarily TDD) a client application which communicates with a TCP server using in a certain application protocol. I've seen in places such as here (1) and here (2) that protocol code should be preferably decoupled from the network code so I each one can be unit-tested separately. However I'm failing to understand how should I design and implement those parts. The first link talks about a MyProtocolHandler class with methods HelloMessage() and