Swift 3 解析查询
Swift 3 Parse query
我将 swift 2 更新为 swift 3
后出现错误
var nicknames = [String]()
var messages = NSArray()
var selectedmsg:PFObject!
query.findObjectsInBackground{
(objects, error) -> Void in
if error == nil
{
messages = objects! ***Cannot assign value of type '[PFObject]?' to type 'NSArray'***
for object in objects! {
self.nicknames.append(object.object(forKey: "userpointer")!.object(forKey: "nickname") as! String) ***Value of type 'Any' has no member 'object'***
}
self.selectedmsg = messages.object(at: (indexPath as NSIndexPath).row) as! PFObject
self.selectedmsg["file"]!.getDataInBackground{ ***Value of type 'Any' has no member 'getDataInBackground'***
***之间的代码有3个错误
代码在 swift 2 中运行良好,有人可以帮我修复 swift 3 中的相同代码吗
请提供任何帮助。
我遇到了同样的问题。我不得不更改以修复我的应用程序在 Swift 3
中的工作
AppDelegate:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
所有准备转场:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
一如既往,不要在Swift中使用NSArray
,除非你别无选择。
NSArray
不提供任何类型信息,因此编译器不知道它实际上包含 PFObject
个对象。
在这种情况下你可以选择!通过将 messages
声明为
来启发编译器
var messages = [PFObject]()
这个小改动将解决所有三个错误。
我将 swift 2 更新为 swift 3
后出现错误var nicknames = [String]()
var messages = NSArray()
var selectedmsg:PFObject!
query.findObjectsInBackground{
(objects, error) -> Void in
if error == nil
{
messages = objects! ***Cannot assign value of type '[PFObject]?' to type 'NSArray'***
for object in objects! {
self.nicknames.append(object.object(forKey: "userpointer")!.object(forKey: "nickname") as! String) ***Value of type 'Any' has no member 'object'***
}
self.selectedmsg = messages.object(at: (indexPath as NSIndexPath).row) as! PFObject
self.selectedmsg["file"]!.getDataInBackground{ ***Value of type 'Any' has no member 'getDataInBackground'***
***之间的代码有3个错误
代码在 swift 2 中运行良好,有人可以帮我修复 swift 3 中的相同代码吗 请提供任何帮助。
我遇到了同样的问题。我不得不更改以修复我的应用程序在 Swift 3
中的工作AppDelegate:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
所有准备转场:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
一如既往,不要在Swift中使用NSArray
,除非你别无选择。
NSArray
不提供任何类型信息,因此编译器不知道它实际上包含 PFObject
个对象。
在这种情况下你可以选择!通过将 messages
声明为
var messages = [PFObject]()
这个小改动将解决所有三个错误。