我将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'***
***
之间的代码中有三个错误代码在swift 2中运行良好,有人可以帮我修复swift 3中的相同代码 如有任何帮助,将不胜感激。
答案 0 :(得分:1)
与往常一样,除非您别无选择,否则不要在Swift中使用NSArray
。
NSArray
不提供任何类型信息,因此编译器不知道它实际上包含PFObject
个对象。
在这种情况下,您可以选择!通过将messages
声明为
var messages = [PFObject]()
这种稍微改变将解决所有三个错误。
答案 1 :(得分:0)
我遇到了同样的问题。我不得不改变以修复我的应用程序在Swift 3中工作
的AppDelegate:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
和所有准备segues:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {