burczyk / ParseCollectionsSwiftBug

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Probable bug in Swift and Parse-iOS-SDK 1.5.0

I have a Swift project where I pin some data to PFUser object. It is an array of PFObject subclasses:

PFUser.currentUser()["posts"] = [post1, post2]

When I try to fetch all the data and cast it to Swift Array it crashes with fatal error: NSArray element failed to match the Swift Array Element type error.

func printCurrentPosts() {
    let posts = PFUser.currentUser()["posts"] as [Post]
    println("posts: \(posts)") //crashes
}

When I cast it to general [PFObject] array it works and prints its content properly.

func printCurrentPostsAsPFObjectArray() {
    let posts = PFUser.currentUser()["posts"] as [PFObject]
    println("posts: \(posts)") //works
}

When I fetch the data in saveAllInBackground: completion closure it can be casted to subclass array without error:

PFObject.saveAllInBackground([post1, post2, PFUser.currentUser()], block: { (success, error) -> Void in
    let posts = PFUser.currentUser()["posts"] as [Post]
    println("posts: \(posts)") //works
})

See ViewController.swift file for implementation. You can run this project in simulator to check each variant.

Using Parse SDK 1.5.0

What am I doing wrong?

About


Languages

Language:Swift 96.1%Language:Objective-C 2.2%Language:Ruby 1.7%