protocols

Using associatedtype in a delegate protocol for a generic type

断了今生、忘了曾经 提交于 2019-12-24 07:50:40
问题 I have a Game class. I made it generic because I was need to support different types of boards. Now I just want to add a classical iOS-style delegate with a method which will take a game and a new points value as parameters. How to achieve this in the Swift associatedtype way? I really confused that I can't impelemnt such simple logic. protocol GamePointsDelegate { associatedtype B: Board func game(_ game: Game<B>, didSetPoints points: Int) } class Game<B: Board> { let board: Board var points

Converting bytes retrieved over a php socket to a integer

ぃ、小莉子 提交于 2019-12-24 07:35:28
问题 I am using the netty API to create a Java server which sends if a client programm sends anything to the server a number like 5. It is a integer with 4 bytes. I think it should be the same like writing an integer into an OutputStream. So I want to receive the integer now by php. But if I call socket_read it outputs nothing helpfull because it does not convert the 4 bytes into a integer. It just uses this as text. If I send a char it works so I need a way in php to convert it. Or would it be

Converting bytes retrieved over a php socket to a integer

邮差的信 提交于 2019-12-24 07:34:46
问题 I am using the netty API to create a Java server which sends if a client programm sends anything to the server a number like 5. It is a integer with 4 bytes. I think it should be the same like writing an integer into an OutputStream. So I want to receive the integer now by php. But if I call socket_read it outputs nothing helpfull because it does not convert the 4 bytes into a integer. It just uses this as text. If I send a char it works so I need a way in php to convert it. Or would it be

Passing data between two view controllers via a protocol

不羁的心 提交于 2019-12-24 06:49:07
问题 How to declare and implement a protocol that will return a view's property? E.g. I have an view called mainView and I want it to be able to return an array when another view, customView for example, asks for it. What I'm doing is that I'm declaring a protocol in the mainView implementation file (with a returnTheArray function) and set the customView to adopt this protocol, but I'm stuck at this point. What should I do to get this working correctly? Or there is a more effective/easy/correct

Cross-platform custom protocol handler tool

为君一笑 提交于 2019-12-24 02:55:16
问题 I'd like my application to be opened whenever a URL of the form appname://some/url/here is opened on Windows, Mac OSX and Ubuntu Linux. There are of course platform specific ways to achieve this but is there a single (say, Python) tool that would accomplish this with minimal fuss? 来源: https://stackoverflow.com/questions/19401424/cross-platform-custom-protocol-handler-tool

Serial port - how to perform safe search for my device?

家住魔仙堡 提交于 2019-12-24 01:49:22
问题 Im writing application that communicate (via serial port) with electronic device which i designed myself. When my PC application starts - it opens available COM ports one by one and it sends some string ("What are you?" for example). My device is programmed, to reply to that "magic question" with own ID (for example: "I am evil device for supervising employees"). When my PC software receive that "magic reply" it starts working normally and its not searching other ports anymore. Of course im

Swift protocol for UIViewController subclasses

我们两清 提交于 2019-12-23 18:07:51
问题 Is it possible to declare a protocol and also define the type of object that can conform to it? I have a set of closures that I'd like to configure in various different subclasses of UIViewController in my project. (They are all related). I'd like to have a factory function that creates the correct type of UIViewController subclass but then returns it as a protocol type. That way I can then configure the various closures and push the view controller onto the navigation controller. I can

In swift, why can't I instantiate a protocol when it has an initialiser?

情到浓时终转凉″ 提交于 2019-12-23 18:06:49
问题 I understand that generally I cannot instantiate a protocol. But if I include an initialiser in the protocol then surely the compiler knows that when the protocol is used by a struct or class later, it will have an init which it can use? My code is as below and line: protocol Solution { var answer: String { get } } protocol Problem { var pose: String { get } } protocol SolvableProblem: Problem { func solve() -> Solution? } protocol ProblemGenerator { func next() -> SolvableProblem } protocol

Swift Xcode 7 beta 5 type cannot refer to itself as a requirement

爱⌒轻易说出口 提交于 2019-12-23 17:40:15
问题 This code used to be legal: protocol Flier { typealias Other : Flier func flockTogetherWith(f:Other) } struct Bird : Flier { func flockTogetherWith(f:Insect) {} } struct Insect : Flier { func flockTogetherWith(f:Insect) {} } Now (in Xcode 7 beta 5) it's not. What's going on here? Is this a bug? I am merely trying to ensure that adopters of Flier declare flockTogetherWith with a parameter that is some adopter of Flier. I've always been able to do that. Why is it suddenly wrong to do? 回答1: I

ArrayLiteralConvertible: Just a normal protocol?

醉酒当歌 提交于 2019-12-23 17:18:55
问题 Trying to understand and appreciate how ArrayLiteralConvertible works... struct Struct<T>: ArrayLiteralConvertible { init(arrayLiteral elements: T...) { for element in elements { print(element) } } } let str: Struct<Int> = [1,2,3] Output: 1 2 3 Now I am trying to do the same thing but this time with my own version of ArrayLiteralConvertible: protocol MyALC { typealias Element init(arrLit elements: Self.Element...) } struct NewStruct<T>: MyALC { init(arrLit elements: T...) { for element in