将Objective-C解析为Swift-iOS
我在尝试将Objective-C代码更改为Swift时遇到问题。这与解析框架有关。如果有人知道下面的代码应该如何用Swift编写,这将对我有很大帮助将Objective-C解析为Swift-iOS,ios,xcode,swift,Ios,Xcode,Swift,我在尝试将Objective-C代码更改为Swift时遇到问题。这与解析框架有关。如果有人知道下面的代码应该如何用Swift编写,这将对我有很大帮助 [user signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) { if (!error) { //The registration was successful, go to the wall [self performSegueWi
[user signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!error) {
//The registration was successful, go to the wall
[self performSegueWithIdentifier:@"SignupSuccesful" sender:self];
}
应该是这样的
user.signUpInBackground {
(success: Bool!, error: NSError!) -> Void in
if !error {
[unowned self] in
self.performSegue("SignupSuccesful", sender:self);
}
编辑:Parse实际上有Swift支持。为了它
Edit2:你不应该在一个块中引用self。改用无主的自我。应该是这样的
user.signUpInBackground {
(success: Bool!, error: NSError!) -> Void in
if !error {
[unowned self] in
self.performSegue("SignupSuccesful", sender:self);
}
编辑:Parse实际上有Swift支持。为了它
Edit2:你不应该在一个块中引用self。使用无主self
。Parse正好在他们的文档中。我想如果我把它摘录到这里,他们会没事的:
user.signUpInBackgroundWithBlock {
(succeeded: Bool!, error: NSError!) -> Void in
if !error {
// Hooray! Let them use the app now.
} else {
let errorString = error.userInfo["error"] as NSString
// Show the errorString somewhere and let the user try again.
}
}
Parse恰好在它们的文档中有。我想如果我把它摘录到这里,他们会没事的:
user.signUpInBackgroundWithBlock {
(succeeded: Bool!, error: NSError!) -> Void in
if !error {
// Hooray! Let them use the app now.
} else {
let errorString = error.userInfo["error"] as NSString
// Show the errorString somewhere and let the user try again.
}
}
[NSObject:Anyobject]?没有名为subscript的成员,将引发解析编译错误 代码应该是这样的,因为userInfor可能是nil
user.signUpInBackgroundWithBlock {
(succeeded: Bool!, error: NSError!) -> Void in
if !(error != nil) {
// Hooray! Let them use the app now.
} else {
if let errorString = error.userInfo?["error"] as? NSString {
println(errorString)
}
}
}
[NSObject:Anyobject]?没有名为subscript的成员,将引发解析编译错误 代码应该是这样的,因为userInfor可能是nil
user.signUpInBackgroundWithBlock {
(succeeded: Bool!, error: NSError!) -> Void in
if !(error != nil) {
// Hooray! Let them use the app now.
} else {
if let errorString = error.userInfo?["error"] as? NSString {
println(errorString)
}
}
}
您可以将他们当前的Objective-C框架连接到Swift。所以他们的框架和Swift一起工作。这不是有效的Swift。类型注释在变量名之后,您不能用
*
表示指针。对不起,我编辑了用户代码,但忘记编辑该部分。您可以将当前的Objective-C框架连接到Swift。所以他们的框架和Swift一起工作。这不是有效的Swift。类型注释在变量名之后,您不能用*
表示指针。对不起,我编辑了用户代码,但忘记编辑该部分。使用Xcode 6.1和iOS 8.1,此解决方案不起作用。请参阅下面的Meshari Alsuhaibani解决方案。该解决方案在使用Xcode 6.1和iOS 8.1时不起作用。请看下面的Meshari Alsuhaibani的解决方案。谢谢你,老兄,你的解决方案解决了我的问题。你甚至可以这样改进你的解决方案:如果让errorString=error.userInfo?[“error”]as?String{谢谢你,老兄,你的解决方案解决了我的问题。你甚至可以改进你的解决方案,比如:如果让errorString=error.userInfo?[“error”]as?String{