I want to set up a delegate to communicate between a view controller and a class. But there's nowhere to assign the delegate because there's not a prepareForSegue type of connection. Where should I put the delegate and how should I implement the code?
Here is the code:
Protocol in Swift:
@objc public protocol translationMadeDelegate: class {
func didGetTranslation(translation:CGPoint)
}
Delegate initialization in viewDidLoad in Swift:
var delegate:translationMadeDelegate?
let trans:CGPoint = CGPointMake(100, 100)
self.delegate!.didGetTranslation(trans)
Objective-C class delegate call
- (void)didGetTranslation:(CGPoint *)translation {
NSLog(@"cgpointed");
}
delegatewill be nil and the app will crash.initmethod of the class.