ios - Parse: fatal error: NSArray element failed to match the Swift Array Element type -
i error (fatal error: nsarray element failed match swift array element type) whenever delete items collection view, close app, relaunch app, , go project. i've found similar solutions re-ordered initializers doesn't seem wok me.
**appdelegate.swift** func application(application: uiapplication, didfinishlaunchingwithoptions launchoptions: [nsobject: anyobject]?) -> bool { // register pfobject subclasses task.registersubclass() task.initialize() project.registersubclass() project.initialize() user.registersubclass() user.initialize() **project.swift** import uikit import parse public class project: pfobject, pfsubclassing { // mark: - public api @nsmanaged public var projecttitle: string! @nsmanaged public var owner: user! @nsmanaged public var tasks: [task] // mark - required pfsubclassing parse setup override public class func initialize() { struct static { static var oncetoken: dispatch_once_t = 0 } dispatch_once(&static.oncetoken) { task.initialize() self.registersubclass() } } public static func parseclassname() -> string { return "project" } // mark: conveinience init init(projecttitle: string, owner: user, tasks: [task]) { super.init() self.projecttitle = projecttitle self.owner = owner self.tasks = tasks } override init() { super.init() } } **task.swift** import uikit import parse public class task: pfobject, pfsubclassing { // mark: - public api @nsmanaged public var title: string @nsmanaged public var ischecked: bool @nsmanaged public var projectowner: project @nsmanaged public var category: string @nsmanaged public var isimportant: bool // mark - required pfsubclassing parse setup override public class func initialize() { struct static { static var oncetoken: dispatch_once_t = 0 } dispatch_once(&static.oncetoken) { self.registersubclass() } } public static func parseclassname() -> string { return "task" } // mark: conveinience init // create new project init(title: string, projectowner: project, ischecked: bool, category: string, isimportant: bool) { super.init() self.title = title self.projectowner = projectowner self.ischecked = ischecked self.category = category self.isimportant = isimportant } override init() { super.init() } }
the error happens when try use tasks
array. load uicollectionview.
here's possibly relevant code grab tasks parse:
// fetch data parse func fetchproject() { let iscurrenttab = navigationcontroller?.tabbaritem.title let tasksquery = pfquery(classname: task.parseclassname()) tasksquery.wherekey("category", equalto: iscurrenttab!) tasksquery.wherekey("projectowner", equalto: project) tasksquery.findobjectsinbackgroundwithblock { (tasks, error) -> void in if error == nil { self.project.tasks.removeall() print(tasks) task in tasks! { print(task) let task = task as! task self.project.tasks.append(task) } self.collectionview?.reloaddata() } else { print("\(error?.localizeddescription)") } } }
i'm using xcode 7.1 , parse v1.8.5
any appreciated!
i ended using pointers access tasks array instead of having nested in projects array. way, make of calls directly array , not lose trying go down nested level.
Comments
Post a Comment