delegates

CreateDelegate with unknown types

∥☆過路亽.° 提交于 2020-02-10 09:01:06
问题 I am trying to create Delegate for reading/writing properties of unknown type of class at runtime. I have a generic class Main<T> and a method which looks like this: Delegate.CreateDelegate(typeof(Func<T, object>), get) where get is a MethodInfo of the property that should be read. The problem is that when the property returns int (I guess this happens for value types) the above code throws ArgumentException because the method cannot be bound. In case of string it works well. To solve the

CreateDelegate with unknown types

亡梦爱人 提交于 2020-02-10 08:58:10
问题 I am trying to create Delegate for reading/writing properties of unknown type of class at runtime. I have a generic class Main<T> and a method which looks like this: Delegate.CreateDelegate(typeof(Func<T, object>), get) where get is a MethodInfo of the property that should be read. The problem is that when the property returns int (I guess this happens for value types) the above code throws ArgumentException because the method cannot be bound. In case of string it works well. To solve the

errors creating a delegate from UISplitViewDetail to master in Swift

我只是一个虾纸丫 提交于 2020-02-08 03:35:06
问题 SWIFT / IOS 8.2 I am trying to set my CalculatorViewController as the delegate target so I can get data - but I seem to be setting it wrong: "EXC_BAD_ACCESS (code:2)" (in GraphView.swift) protocol CalculatorViewDataSource: class { func calculateYForXEquals(sender: CalculatorViewController, currentX: CGFloat) ->CGFloat? } class GraphView: UIView { weak var calculatorViewDataSource: CalculatorViewDataSource? //... } (in GraphViewController.swift) class GraphViewController: UIViewController {

how to set protocol function not properly invoke in DataProvider class Alamofire function swift

筅森魡賤 提交于 2020-02-06 08:01:40
问题 I need to set protocol function in Alamofire download function to track and observe progress fraction value. I have to tried to implement delegate function but its not properly executes giving error. I have one DataProvider class which has Alamofire function and then I am calling this in ViewController. Errors getting on init(webService: DataProvider = DataProvider()) : 'self' used before 'super.init' call 'super.init' isn't called on all paths before returning from initializer ViewController

how to set protocol function not properly invoke in DataProvider class Alamofire function swift

纵然是瞬间 提交于 2020-02-06 08:00:30
问题 I need to set protocol function in Alamofire download function to track and observe progress fraction value. I have to tried to implement delegate function but its not properly executes giving error. I have one DataProvider class which has Alamofire function and then I am calling this in ViewController. Errors getting on init(webService: DataProvider = DataProvider()) : 'self' used before 'super.init' call 'super.init' isn't called on all paths before returning from initializer ViewController

How do you use the Delegate Protocol Pattern with SpriteKit?

删除回忆录丶 提交于 2020-02-06 07:59:28
问题 So I have one UIViewController and two SKScene s. The UIViewController present the two scenes by rotating the device; landscape load SKScene 1 and portrait load SKScene 2 lie this: override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { print("TRIGGERED") if UIDevice.current.orientation.isLandscape { print("Landscape") presentView(name: "GameScene") } else { print("Portrait") presentView(name: "GameScene2") } super.viewWillTransition(to:

How do you use the Delegate Protocol Pattern with SpriteKit?

两盒软妹~` 提交于 2020-02-06 07:59:05
问题 So I have one UIViewController and two SKScene s. The UIViewController present the two scenes by rotating the device; landscape load SKScene 1 and portrait load SKScene 2 lie this: override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { print("TRIGGERED") if UIDevice.current.orientation.isLandscape { print("Landscape") presentView(name: "GameScene") } else { print("Portrait") presentView(name: "GameScene2") } super.viewWillTransition(to:

Convert Func<DerivedType, Object> to Func<BaseType, Object>

别来无恙 提交于 2020-02-04 14:33:07
问题 What is the best way to convert from a delegate that takes a first parameter of a derived type into one that receives a base type? What I mean is: Func<DerivedType, Object> original = ...; Func<BaseType, Object> converted = Something(original); Casts, of course, do not work, since these are actually two different types. 回答1: Since you want to pass a base type to a method that takes a derived type, you need to add a cast. If you know that all calls to converted would be passing DerivedType ,

Delegating Objective-C Protocol on Swift

こ雲淡風輕ζ 提交于 2020-02-03 08:40:31
问题 I'm implementing an UDP Listener on iOS using the Swift language. For this I'm relaying on the CocoaAsyncSocket project. I was succeeded on importing the CocoaAsyncSocket library using a Bridging-Header.h, I could call the functions from the Objective-C classes, but I'm not able to write the delegate function on swift. This is the code where I set the Socket and define the ViewController.swif as the delegate class for the listener: func setupSocket() { var udpSocket : GCDAsyncUdpSocket =

Delegating Objective-C Protocol on Swift

有些话、适合烂在心里 提交于 2020-02-03 08:38:21
问题 I'm implementing an UDP Listener on iOS using the Swift language. For this I'm relaying on the CocoaAsyncSocket project. I was succeeded on importing the CocoaAsyncSocket library using a Bridging-Header.h, I could call the functions from the Objective-C classes, but I'm not able to write the delegate function on swift. This is the code where I set the Socket and define the ViewController.swif as the delegate class for the listener: func setupSocket() { var udpSocket : GCDAsyncUdpSocket =