I am new to objective C and swift , and have chosen the swift route . I am trying to convert this objective C example to swift and am failing.
Can someone tell me where I am going wrong?
//obj-c
- (void)didTapButton {
[[Digits sharedInstance] authenticateWithCompletion:^
(DGTSession* session, NSError *error) {
if (session) {
// Inspect session/error objects
}
//swift
@IBAction func loginTouched(sender: AnyObject) {
var dg = Digits.sharedInstance()
dg.authenticateWithCompletion { (session: DGTSession!, error: NSError!) in
//code
}
}
I am doing something totally wrong, and would appreciate any help. Here's the error.
2014-10-28 00:29:11.754 testign[49947:1809207] -[testign.ViewController loginTouched]: unrecognized selector sent to instance 0x7fba9a542190
2014-10-28 00:29:11.757 testign[49947:1809207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[testign.ViewController loginTouched]: unrecognized selector sent to instance 0x7fba9a542190'
try this
@IBAction func loginTouched(sender: AnyObject) {
var dg = Digits.sharedInstance()
dg.authenticateWithCompletion({ (session: DGTSession!, error: NSError!) -> Void in
//code
})
}
import UIKit
import TwitterKit
class ViewController: UIViewController {
var dg = Digits.sharedInstance()
override func viewDidLoad() {
super.viewDidLoad()
}
//login to digits.
@IBAction func loginTouched(sender: AnyObject) {
dg.authenticateWithCompletion { (session: DGTSession!, error: NSError!) in
if session != nil {
println("Logged in with session:" + session.authToken)
} else {
println("Session object is nil")
}
}
}
//logout of digits.
@IBAction func logoutTouched(sender: AnyObject) {
dg.logOut()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.