EXC_BAD_ACCESS when accessing computed property NSManagedObject

I have defined a class that has a computed property. When I try to access a property in my code, I get EXC_BAD_ACCESS

. I set a breakpoint on the property getter and noticed that it was never called. I don't know what is causing this. I can access other properties of the object.

Here is the code

import UIKit
import CoreData

@objc(Person)

class Person: NSManagedObject {

    struct Keys {
        static let Name = "name"
        static let ProfilePath = "profile_path"
        static let Movies = "movies"
        static let ID = "id"
    }

    @NSManaged var name: String
    @NSManaged var id: NSNumber
    @NSManaged var imagePath: String?
    @NSManaged var movies: [Movie]

    override init(entity: NSEntityDescription, insertIntoManagedObjectContext     context: NSManagedObjectContext?) {
    super.init(entity: entity, insertIntoManagedObjectContext: context)
}



init(dictionary: [String : AnyObject], context: NSManagedObjectContext) {

    let entity = NSEntityDescription.entityForName("Person", inManagedObjectContext: context)!

    super.init(entity: entity, insertIntoManagedObjectContext: context)



    name = dictionary[Keys.Name] as! String
    id = dictionary[Keys.ID] as! Int
    imagePath = dictionary[Keys.ProfilePath] as? String
}

var image: UIImage? {
    get {
        return TheMovieDB.Caches.imageCache.imageWithIdentifier(imagePath)
    }

    set {
        TheMovieDB.Caches.imageCache.storeImage(image, withIdentifier: imagePath!)
    }
}
}

      

This is how I am trying to access the image property and get

Execution was interrupted, reason: EXC_BAD_ACCESS (code = 1, address = 0x20)

When I do actor.image

. actor

is a class object Person

and initialized correctly. I put a breakpoint on the getter for the image property and it never gets called.

if let localImage = actor.image {
            cell.actorImageView.image = localImage
        } else if actor.imagePath == nil || actor.imagePath == "" {
            cell.actorImageView.image = UIImage(named: "personNoImage")
    }

      

What am I doing wrong?

+3


source to share


1 answer


I just figured out the problem, I didn't set the class for the object in the data model inspector. This solved it



+3


source







All Articles