protocols

How can I call a static function on a protocol in a generic way?

房东的猫 提交于 2020-01-22 10:32:53
问题 Is there a point to declaring a static function on a protocol? The client using the protocol has to call the function on a type conforming to the protocol anyway right? That breaks the idea of not having to know the type conforming to the protocol IMO. Is there a way to call the static function on the protocol in a way where I don't have to know the actual type conforming to my protocol? 回答1: Nice question. Here is my humble point of view: Is there a point to declaring a static function on a

How can I call a static function on a protocol in a generic way?

冷暖自知 提交于 2020-01-22 10:30:14
问题 Is there a point to declaring a static function on a protocol? The client using the protocol has to call the function on a type conforming to the protocol anyway right? That breaks the idea of not having to know the type conforming to the protocol IMO. Is there a way to call the static function on the protocol in a way where I don't have to know the actual type conforming to my protocol? 回答1: Nice question. Here is my humble point of view: Is there a point to declaring a static function on a

Swift - protocol as type as target of button action

醉酒当歌 提交于 2020-01-22 02:01:06
问题 I am trying to create - HeaderView which is subclass of UIView, it contains a close button and a title label. class HeaderView: UIView { private var titleLabel: UILabel! private var closeButton: UIButton! } I don't want to add self as target of closeButton action but want to set myViewController as its target, moreover I want HeaderView class to be reusable. So I declared a protocol: protocol CloseViewProtocol { func closeViewAction(sender: UIButton!) } And declared a variable like this:

how to set a node to sleep in ns2

不羁的心 提交于 2020-01-17 12:38:31
问题 I just want to set a node to sleep in ns-2 and i have searched in protocols and i found a lot of objects and functions about sleep but i couldn't use them in other protocols to set a node to sleep. when i use them i get Segmentation fault or Floating point and i know what these errors mean but i can't find a way to solve them. Like when i use sleep() function from SMAC. I have searched in google and after a week i still didn't find any solution...! could you guys please help me here...? 回答1:

how to set a node to sleep in ns2

谁说胖子不能爱 提交于 2020-01-17 12:38:18
问题 I just want to set a node to sleep in ns-2 and i have searched in protocols and i found a lot of objects and functions about sleep but i couldn't use them in other protocols to set a node to sleep. when i use them i get Segmentation fault or Floating point and i know what these errors mean but i can't find a way to solve them. Like when i use sleep() function from SMAC. I have searched in google and after a week i still didn't find any solution...! could you guys please help me here...? 回答1:

How to declare Dictionary<String, Decimal> complies to protocol

◇◆丶佛笑我妖孽 提交于 2020-01-17 06:51:34
问题 I've defined a protocol: public protocol VariableTable { subscript(key:String) -> Decimal? { get set } } which merely indicates that a VariableTable has to provide a subscript operator for String->Decimal. Obviously, Dictionary<String, Decimal> meets that requirement. How do I let the compiler know that? extension Dictionary<String, Decimal> : VariableTable {} yields: Constrained extension must be declared on the unspecialized generic type 'Dictionary' with constraints specified by a 'where'

can i share Facebook user.name and user.id with multiple views

喜夏-厌秋 提交于 2020-01-17 06:19:14
问题 i have worked on this project for a couple of months and i have only been programming for about a year so im not to smart on this subject so please be patient, i have create a login with Facebook and once i fetch the user info i have created a method to parse the info to the login view and i place this method in the and this method pushes to the loginViewController once it has received the info, im try to pass the same info to the settingViewController to show the name and the pic which is

Swift protocol extension

旧街凉风 提交于 2020-01-17 03:22:06
问题 Very much appreciated the article about getting rid of using strings when instantiating UIViewController or UIStoryboard . Though there is one point where I wanted to change the behavior. Instead of giving a Storyboard enum into the class method for getting a storyboard, I wanted a type here that conforms to a protocol. extension UIStoryboard { class func storyboard(storyboard: StoryboardRepresentable, bundle: NSBundle? = nil) -> UIStoryboard { return UIStoryboard(name: storyboard

Releasing a parameter

强颜欢笑 提交于 2020-01-17 01:21:31
问题 let's say if you have class doing something on some other thread. And has delegate of its own. @protocol XRequestDelegate; @interface XRequest : NSObject { id<XRequestDelegate> delegate; } @property (nonatomic, retain) id<XRequestDelegate> delegate; - (void) doSomething; @end @protocol XRequestDelegate <NSObject> - (void)request:(XRequest *)request didFinish:(id)object; - (void)request:(XRequest *)request didFailWithError:(NSError*)error; @end doSomething eventually calls either request

Design patterns for network protocols?

守給你的承諾、 提交于 2020-01-14 04:09:12
问题 So I'm building a fairly simple file transfer server/client but having a hard time to figure out a good design for processing different commands and states within the protocol.. Say that you have 3 different commands upload , remove , download , you could use 3 different if-statements and keep track of states with additional if-statements, but that wont scale and will be impossible to maintain.. The Chain Of Responsibility design pattern could be used for sequential stuff such as encryption