protocols

Why do I not need to declare UIAlertViewDelegate in the header?

六月ゝ 毕业季﹏ 提交于 2020-01-03 16:43:09
问题 I thought I had finally managed to understand the concept of a delegate until the following occurred: I changed my header file to remove the reference to the delegate and the Alert still worked. The only difference is that I lose code hinting. //.h #import <UIKit/UIKit.h> //@interface ViewController : UIViewController <UIAlertViewDelegate> @interface ViewController : UIViewController - (IBAction)showMessage:(id)sender; @end //.m #import "ViewController.h" @implementation ViewController -

How to declare a generic protocol property requirement in a protocol

独自空忆成欢 提交于 2020-01-03 06:33:07
问题 Struggling for a while with, it will be really helpful if you can shed some light on this: I have an APIWorkerProtocol which has a property requirement, the required property is a protocol i.e DataParserProtocol protocol APIWorkerProtocol { var apiRequestProvider : APIRequestGeneratorProtocol {get} var dataParser : DataParserProtocol{get} func callAPI(completionHandler: @escaping (APICallResult<Self.ResultType>) -> Void) } protocol DataParserProtocol { associatedtype ExpectedRawDataType

Checking for protocol availability in Swift

▼魔方 西西 提交于 2020-01-03 00:32:12
问题 I am adopting WatchConnectivity, but I am still supporting iOS7 and iOS 8 for which this library is not available. Moreover I am adopting protocol WCSessionDelegate also not supported but this older systems. In ObjectiveC I would have used preprocessing directives to shield this declaration and the protocol adoption from versions not supporting them. How do I handle that in Swift so that the app does not crash on older systems? 回答1: I thank @joern for the suggestion of adopting the protocol

Swift 1.2 error on Objective-C protocol using getter

前提是你 提交于 2020-01-02 23:19:11
问题 This Objective-C protocol used to work in Swift 1.1, but now errors in Swift 1.2. Objective-C Protocol stripped down to the one problematic property: @protocol ISomePlugin <NSObject> @property (readonly, getter=getObjects) NSArray * objects; @end class SomePlugin: NSObject, ISomePlugin { var objects: [AnyObject]! = nil func getObjects() -> [AnyObject]! { objects = ["Hello", "World"]; return objects; } } Here is the Swift 1.2 error: Plugin.swift:4:1: error: type 'SomePlugin' does not conform

have to create java pojo for the existing proto includes Map

妖精的绣舞 提交于 2020-01-02 10:04:36
问题 I have tried converting proto to java pojo . But got the error [Stderr] Order.proto:12:18: Expected "required", "optional", or "repeated". [Stderr] Order.proto:12:21: Expected field name. optional int32 orderID = 1; optional int32 quantity = 2; map<string,string> map_field = 4; repeated string product = 3; Please help me what needs to be changed. i searched on google protobuf developer site https://developers.google.com/protocol-buffers/docs/proto#maps It says that Map fields cannot be

Xamarin Macintosh Customer URL protocol handle passed parameter

こ雲淡風輕ζ 提交于 2020-01-02 09:53:58
问题 I've written a Macintosh app that handles a custom protocol: <key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLName</key> <string>My Cool Handler</string> <key>CFBundleURLSchemes</key> <array> <string>coolhandler</string> </array> </dict> </array> All well and good. It launches. However, I'm clicking on a link like this: coolhandler://Iwant/toparse/this In Windows, the registry entry is simple and this work just fine. When my Windows app launches, the whole url is passed as an

Xamarin Macintosh Customer URL protocol handle passed parameter

和自甴很熟 提交于 2020-01-02 09:52:16
问题 I've written a Macintosh app that handles a custom protocol: <key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLName</key> <string>My Cool Handler</string> <key>CFBundleURLSchemes</key> <array> <string>coolhandler</string> </array> </dict> </array> All well and good. It launches. However, I'm clicking on a link like this: coolhandler://Iwant/toparse/this In Windows, the registry entry is simple and this work just fine. When my Windows app launches, the whole url is passed as an

How to write a generic function for floating point values in swift

人走茶凉 提交于 2020-01-02 08:01:59
问题 I would like to call floating point methods on floating point types in swift. func example<T : FloatingPoint>(_ x:T) -> T { return cos(cbrt(x + 1)) } Is there a better way to do so than this? protocol SupportsFloatingPoint : FloatingPoint { var cubeRoot:Self { get } var cosine:Self { get } } extension Double : SupportsFloatingPoint { var cubeRoot:Double { return Darwin.cbrt(self) } var cosine:Double { return Darwin.cos(self) } } extension Float : SupportsFloatingPoint { var cubeRoot:Float {

Protocol can only be used as a generic constraint

我的梦境 提交于 2020-01-02 05:42:07
问题 I have a MapViewController for presenting annotations on map. It contains an object of type MapPresentable. protocol MapPresentable { associatedtype AnnotationElement: MKAnnotation var annotations: [AnnotationElement] { get } } class MapViewController<M: MapPresentable>: UIViewController { var mapPresentable: M! } MapViewController can also present route on map in case mapPresentable conforms to RoutePresentable protocol. protocol RoutePresentable: MapPresentable { var getRouteLocations:

Where can I learn about the “shell:” URI?

这一生的挚爱 提交于 2020-01-02 02:26:06
问题 I just realised there is a shell: URI, but every search engine seems to think shell: and shell are the same thing. The only thing I've found out is that you can type shell:startup right in explorer (XP & 7 tested) for obvious effects. This is good already because there is no %startup% , but I want to know what else is this capable of. Is there any MS reference on this? EDIT (even if it's not on MSDN) 回答1: Stuart seems to have found a fairly thorough list of the folders; I'll speak to the