protocols

How can you provide default implementations for UIPageViewControllerDataSource?

前提是你 提交于 2019-12-19 04:09:44
问题 I assume that the answer to this question will address issues with Objective-C protocols in general, but this is the first problem of this type that I've come across. I expect for these methods to be used, when implementing UIPageViewControllerDataSourceWithConnections . import UIKit protocol UIPageViewControllerDataSourceWithConnections: UIPageViewControllerDataSource { var connectedViewControllers: [UIViewController] {get} } extension UIPageViewControllerDataSourceWithConnections { func

An id conforming to the protocol vs Qualify an id with a protocol

丶灬走出姿态 提交于 2019-12-19 04:02:57
问题 I was going through Programming with Objective-C document provided by Apple. I'm trying to understand the following paragraph, but so far, unable to do so. @protocol XYZPieChartViewDataSource - (NSUInteger)numberOfSegments; - (CGFloat)sizeOfSegmentAtIndex:(NSUInteger)segmentIndex; @optional - (NSString *)titleForSegmentAtIndex:(NSUInteger)segmentIndex; @required - (UIColor *)colorForSegmentAtIndex:(NSUInteger)segmentIndex; @end @interface XYZPieCharView : UIView @property (weak) id

Swift: How can I make a function with a Subclass return type conform to a protocol, where a Superclass is defined as a return type?

倾然丶 夕夏残阳落幕 提交于 2019-12-19 03:42:10
问题 I have a protocol, where a function is defined, the return type of a function is a SuperclassType . In a class which conforms to the protocol I'm trying to define this function, but with a SubclassType return type. Compiler tells me, that this class does not conform to the protocol, because obviously SubclassType != SuperclassType protocol SomeProtocol { func someFunction(someParameter:SomeType) -> SuperclassType? } class SomeClass : SomeProtocol { func someFunction(someParameter:SomeType) ->

Combining Clojure defprotocol and defrecord

依然范特西╮ 提交于 2019-12-19 03:10:24
问题 As far as I can tell, if I want to define a protocol ( defprotocol ) that will only be implemented by one defrecord , I still have to define the protocol first, then define the defrecord that implements it: (defprotocol AProtocol (a-method [this]) (b-method [this that])) (defrecord ARecord [a-field b-field] AProtocol (a-method [this] ...) (b-method [this that] ...)) Is there no way to combine the two, perhaps with an "anonymous" protocol? 回答1: Don't do this. A "private" or "anonymous"

Unable to use custom class in a protocol with @objc attribute?

廉价感情. 提交于 2019-12-18 19:39:22
问题 I am trying to create a protocol for JSON loading delegation, JSONLoaderDelegate . My other class, called JSONLoader , is supposed to dispatch events to its delegate (that implements the JSONLoaderDelegate protocol) like: self?.delegate?.jsonLoaderdidEndWithError(self!, error: JSONLoaderError.LoadError) The implementation of the JSONLoader is not that important (imho). However I seem to have problems to implement the protocol, this is the code: @objc protocol JSONLoaderDelegate { optional

Swift Protocol - Property type subclass

陌路散爱 提交于 2019-12-18 18:51:59
问题 I'm defining a protocol called PanelController in which I'd like to store a PanelView . PanelView itself is a subclass of UIView and defines the basic structure of panel. I have three different views that subclass PanelView : LeftPanel , MidPanel , and RightPanel . For each of those panels I'd like to define a xxxPanelController (left, mid, right) that conforms to the PanelController protocol. The issue I'm running up against is in the protocol and xxxPanelController protocol PanelController

How to declare a property of a particular class which is also protocol conformant?

泪湿孤枕 提交于 2019-12-18 15:08:15
问题 Suppose I want to create a property which is a subclass of UIViewController and also conformant to the protocol MyDelegateProtocol. In Objective-C I would write something like: @property (strong, nonatomic) UIViewController<MyDelegateProtocol> *delegate; However, I'm not sure how to write this in Swift. I know how to declare a property which is protocol-conformant, or a property which is of a particular type: let delegate : MyDelegateProtocol? let delegate : UIViewController? But I can't

Is there an Application URL Protocol for MS Word?

血红的双手。 提交于 2019-12-18 14:53:43
问题 I'm working on a javascript front end site to run in the browser [Chrome], and I'd like to launch Word on the clients PC with their selected macros that have already been setup in Word for them on their pc. My questions is does Office [and Word] create an Application URL Protocol [MSDN how to article] for itself when installing it? For example, iTunes does this, with the url 'itmss://itunes.apple.com/us/app/123213213?mt=8' which, if the user has installed iTunes, will prompt them to open it.

How to detect an incoming SSL (https) handshake (SSL wire format)?

余生长醉 提交于 2019-12-18 12:20:30
问题 I'm writing a server which is accepting incoming TCP connections. Let's suppose the server has accepted a TCP connection, and has already received 16 (or so) bytes from the client. Knowing those 16 bytes how can the server detect whether the client wants to initiate an SSL handshake? I've made an experiment, which showed that on my Linux system connecting to localhost (either 127.0.0.1 or AF_UNIX) via SSL makes the client send the following handshake (hexdump), followed by 16 seemingly random

How to define and implement properties in protocol

∥☆過路亽.° 提交于 2019-12-18 11:23:53
问题 I want to define one protocol with few properties and need to use those properties in another NSObject subclass. Please give me link or example code. I need that to work with 10.5. Thanks PLEASE CHECK THE FOLLOWING SAMPLE CODE @protocol MyProtocol @property (nonatomic, readonly) id someObject; @property (nonatomic, getter=isAlive) BOOL alive; @end #import "MyProtocol.h" @interface MyCustomClass : NSObject <MyProtocol>{ } @end #import "MyCustomClass.h" @implementation MyCustomClass @synthesize