protocols

Method customization in sub class not called

柔情痞子 提交于 2019-12-09 23:57:43
问题 It seems that a function defined as a customization point in a protocol with a default implementation in protocol extension cannot be customized in a subclass that inherits the protocol indirectly via a base class if that base class did not customize the function at the first place. Here is a simple protocol: protocol MyProtocol { func myFunc() -> String } With a default implementation: extension MyProtocol { func myFunc() -> String { return "hello from extension" } } Let's create a base

Meta language to code generate packed structs for ANSI-C and C# Structs

青春壹個敷衍的年華 提交于 2019-12-09 23:14:38
问题 I'm trying to find a "meta language" that can be used to define a structure and get/set code for members. The catch is that the structure already exists in code, and this "meta language" would serve as bit-for-bit replacement of the original hand-coded structure to allow the headers describing the structures to be generated. The point is that the structures are used as part of a protocol between a C# application and an embedded device (not linux based, think smaller and more constrained like

Protocol Having generic function and associatedType

﹥>﹥吖頭↗ 提交于 2019-12-09 20:17:50
问题 I've the following code: protocol NextType { associatedtype Value associatedtype NextResult var value: Value? { get } func next<U>(param: U) -> NextResult } struct Something<Value>: NextType { var value: Value? func next<U>(param: U) -> Something<Value> { return Something() } } Now, the problem is in the Something implementation of next . I want to return Something<U> instead of Something<Value> . But when I do that I got the following error. type 'Something<Value>' does not conform to

Swift protocol with constrained associated type error “Type is not convertible”

佐手、 提交于 2019-12-09 18:16:48
问题 I have created 2 protocols with associated types. A type conforming to Reader should be able to produce an instance of a type conforming to Value . The layer of complexity comes from a type conforming to Manager should be able to produce a concrete Reader instance which produces a specific type of Value (either Value1 or Value2 ). With my concrete implementation of Manager1 I'd like it to always produce Reader1 which in turn produces instances of Value1 . Could someone explain why "Reader1 is

iOS 5.0 Warning: Cannot find protocol definition for Delegate

人盡茶涼 提交于 2019-12-09 17:39:12
问题 I have custom UIView class GestureView. I have a forward declaration for this class and it's delegate below. I have imported GestureView.h in .m file. This works fine but iOS gives warning message saying "Cannot find protocol definition for GestureViewDelegate". If I remove forward declaration it gives same warning message as error. I don't want to import GestureView.h from ContainerViewController.h as I usually imports stuffs in .m file. Could someone please explain what's wrong in following

Swift protocol for string interpolation

点点圈 提交于 2019-12-09 14:45:44
问题 What protocol do I have to implement to control the way an object is represented within a string interpolation in Swift? I wan't to specify what get's printed in something like this: struct A{ } var a = A() println("\(a)") 回答1: You need to implement the Printable protocol: This protocol should be adopted by types that wish to customize their textual representation. This textual representation is used when objects are written to an OutputStreamType . protocol Printable { var description:

HTTP: max length of etag

╄→尐↘猪︶ㄣ 提交于 2019-12-09 14:09:32
问题 Does the HTTP protocol specify a max length for the ETag? 回答1: No. 14.19 ETag The ETag response-header field provides the current value of the entity tag for the requested variant. The headers used with entity tags are described in sections 14.24, 14.26 and 14.44. The entity tag MAY be used for comparison with other entities from the same resource (see section 13.3.3). ETag = "ETag" ":" entity-tag Examples: ETag: "xyzzy" ETag: W/"xyzzy" ETag: "" 回答2: No, an entity-tag is a quoted-string with

How can we implement concurrency thread using protocol in swift? [closed]

妖精的绣舞 提交于 2019-12-09 14:05:33
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . I was asked this question in interview for iOS developer role. // Please design a read-write task queue where you can tag the reader task with label, // where the the task with the same label should be executed sequentially, and the // tasks with different labels could be executed

How to pass data between UIViewControllers with protocols/delegates

牧云@^-^@ 提交于 2019-12-09 13:05:13
问题 In the code below I have a ViewController ("SenderViewController"), which passes a message to the main ViewController when a button is tapped. What I don't fully understand is how does messageData() method in the main ViewController know when to listen for the message. Can someone please explain me what is triggering the messageData() method in the main ViewController ? SenderViewController: import UIKit protocol SenderViewControllerDelegate { func messageData(data: AnyObject) } class

Send multiple application protocols requests ( Similar to mailto: )

≡放荡痞女 提交于 2019-12-09 10:43:41
问题 I work with an application that has created it's own protocol such like MS did for its MSN client msnim:chat?contact=test@test.com However, I need to create a PHP or javascript (or combo) to basically send 3 requests to the protocol as soon as possible. I also want it if the end result is www.test.com/send.php that a user link <a href='www.test.com/send.php'> would not pop up or redirect to a page much like doing <?php header('Location: msnim:chat?contact=test@test.com'); ?> would not create