felix696
(Kirti Shilwant)
1
The instructions say:
Create TTLock object, which must comply with the protocol
This is what I have done:
import TTLock
class ViewController: UIViewController, TTSDKDelegate {
var TTObject : TTLock!
override func viewDidLoad() {
super.viewDidLoad()
TTObject.delegate = self as TTSDKDelegate
}
}
I wanted to know if it is correct.
tkrajacic
(Thomas Krajacic)
2
In general your idea is correct, but there are a few possible bugs/pitfalls here
A few notes inline.
(you can use the preformatted block feature of the editor here to format code by the way)
class ViewController: UIViewController, TTSDKDelegate {
// In Swift it is customary to start variable names with lower case letters.
// Of course you are free to deviate from this convention and use your preferred style
//
// You are never actually assigning an instance here.
// Is this intentional?
var ttObject : TTLock!
// If `ttObject` will be passed in from the outside you could just
// make it a regular `Optional` (`TTLock?`) to be on the safe side.
override func viewDidLoad() {
super.viewDidLoad()
// If `ttObject` was never assigned an actual instance of type `TTLock`
// this following line will try to set the `delegate` on something that is `nil` and crash.
// Also, the compiler knows that `self` is a `TTSDKDelegate`, as you told it in your
// first line where you declare the ViewController.
// So you can remove the `as TTSDKDelegate` here.
ttObject.delegate = self as TTSDKDelegate
}
}
3 Likes
How do you use the preformatted block format because some of us can't really use it
tkrajacic
(Thomas Krajacic)
4
This seems to be a pretty good overview of the features
3 Likes