protocols

Swift 3.0 Delegate Protocol doesn't work

不问归期 提交于 2020-01-05 04:40:13
问题 I have made delegate protocol within two view controllers. but the delegate method doesn't call on my code snippet. what is the reason for that. I couldn't find out the issue kindly post your suggestions to relive this issue. Main View controller class ViewController: UIViewController, testDelegateMethod { override func viewDidLoad() { super.viewDidLoad() let vw = testViewController() vw.delegateTest = self let push = self.storyboard?.instantiateViewController(withIdentifier:

Why do classes need to be “final” when adopting a protocol with a property with type “Self”?

北战南征 提交于 2020-01-05 04:04:05
问题 I can use generic protocols just fine, but am trying to grasp the reasoning behind some limitations of generic protocols. Example: internal protocol ArchEnemyable { var archEnemy: Self? { get } } internal final class Humanoid: ArchEnemyable { internal var archEnemy: Humanoid? // is the adoption to Self, works only when class is final internal init(otherOne pOtherOne: Humanoid?) { self.archEnemy = pOtherOne } } I do not find any example where it would not work, when it is not final. Do one of

Protocols versus polymorphism in swift

我的梦境 提交于 2020-01-04 05:51:54
问题 I am rather new to object-oriented programming and I am attempting to wrap my head around protocols, delegates, and polymorphism. I recently watched a training video that promoted that when you have two classes that are similar with similar method implementations, a protocol is the best solution for achieving this elegantly. That makes sense. However, some additional research has led me to discover polymorphism and it sounds like that is also a preferred approach, whereas you could simply use

Accessing protocol property in Swift class

大兔子大兔子 提交于 2020-01-04 05:33:35
问题 I am trying to use a protocol to pass an array from one class to another. protocol PinsArray { var dataArray: [LocationPost] {get set} } When I am trying to create a delegate in class, which should receive it does not work. I cannot access the property var delegate = PinsArray.self Like this: delegate.dataArray It says that "instance member 'dataArray' cannot be used on type PinArray" So what do I do wrong? 回答1: You are assigning the type of PinsArray to delegate instead of assigning an

Determine Remote Desktop Protocol version programmatically?

匆匆过客 提交于 2020-01-04 05:09:12
问题 Remote Desktop Protocol version 6.1 changed the way RDP sessions are handled (making session 0, which previously meant "console session", into a non-interactive session). I need to be able to figure out from within my program how to determine just what version of the RD protocol is being used on the current RDP session. Nothing I can find in the Windows Terminal Services API, however, seems to give me the protocol version. 回答1: the WTSClientBuildNumber attribute in the WTS_INFO_CLASS contains

Swift where condition to check if a property is implemented

ぐ巨炮叔叔 提交于 2020-01-04 04:14:06
问题 I just found another way to make a great use of protocols and protocol extensions in Swift by extending the Optional protocol to add a function so I can provide default values. I wrote a blog post about this here: https://janthielemann.de/random-stuff/providing-default-values-optional-string-empty-optional-string-swift-3-1/ The gist of the post is that I needed a clean and easy way to provide default values for optional String which are nil or empty. To do this, I created a Emptyable protocol

How can you mirror the design of the Codable/CodableKeys protocols?

核能气质少年 提交于 2020-01-03 18:37:32
问题 I'm trying to achieve something similar to how Swift utilizes the CodableKeys protocol set on an enumeration defined within a class that implements Codable . In my case, the class is CommandHandler and the enumeration is CommandIds and it doesn't require on code-gen from the compiler as the enum will always be explicitly specified. Here's a simplified version of what I'm after... protocol CommandId{} protocol CommandHandler{ associatedtype CommandIds : CommandId, RawRepresentable } class

How can you mirror the design of the Codable/CodableKeys protocols?

て烟熏妆下的殇ゞ 提交于 2020-01-03 18:37:30
问题 I'm trying to achieve something similar to how Swift utilizes the CodableKeys protocol set on an enumeration defined within a class that implements Codable . In my case, the class is CommandHandler and the enumeration is CommandIds and it doesn't require on code-gen from the compiler as the enum will always be explicitly specified. Here's a simplified version of what I'm after... protocol CommandId{} protocol CommandHandler{ associatedtype CommandIds : CommandId, RawRepresentable } class

Protocol to force variable declaration - Objective C

自古美人都是妖i 提交于 2020-01-03 17:47:08
问题 Is it possible to declare variable in @protocol? Just to force programmers to add those variable in implementing class's(classes which implements this protocol) header and implementation? Thanks 回答1: Short answer: No, it isn't possible to do that . You can enforce the availability of methods and properties at most. 回答2: You can't declare ivars in @protocol s but you can force the conforming class to implement an accessor and a mutator, which sounds like what you're getting at. For example:

Fail in assigning self.delegate it produce unrecognized selector sent

ⅰ亾dé卋堺 提交于 2020-01-03 17:02:55
问题 I'm a new in iOS, and I have trouble in implementing @protocol so sorry if you think this is an easy thing.. i've been searching around stackoverflow.com, the webs and also try uncle Google for a while and I decided to ask here... The main idea is calling a MyViewController from TopViewController and do flip animation I Start with creating the protocols.. // This is my Delegate header // MyViewController.h @protocol MyViewControllerlDelegate - (void) myViewControllerDidFinish; @end @interface