I am upgrading my app to iOS 10 / swift 3
So constructing an
NSManagedObject
with a dictionary (values received from remote db) this way...let writerDictionary = [
...: ...,
...: ...,
...:...
]
let newWriter = Writer(dictionary: wirterDictionary, context: shared_context)
isFavorite is an @
NSManaged
property of Writer the NSManagedObject subclass. I set isFavorite like this:newWriter.isFavorite = true
right after constructing the
newWriter
object before saving the context.This line crashes with Uncaught Exception "libc++abi.dylib: terminating with uncaught exception of type NSException" in iOS 10
I also tried:
newWriter.setValue(true, forKey: "isFavorite")
It doesn't crash - but the bool value doesn't change?
Previously there was no problem whatsoever with iOS 9
This is the Writer sublclass:
import UIKit
import CoreData
@objc(Writer)
class Writer: NSManagedObject {
/
@NSManaged var id: NSNumber
@NSManaged var name: String
@NSManaged var picture: String?
@NSManaged var publicationID: NSNumber
@NSManaged var language: String
@NSManaged var country: String
@NSManaged var lastArticle: Date
@NSManaged var isFavorite: Bool /
/
@NSManaged var hasNewArticles: Bool
/
@NSManaged var publication: Publication
@NSManaged var articles: [Article]
var writerImage: UIImage? {
get {
return ImageCache.sharedCache.imageWithIdentifier("writers-" + String(id))
}
set {
ImageCache.sharedCache.storeImage(newValue, withIdentifier: "writers-" + String(id))
}
}
override init(entity: NSEntityDescription, insertInto context: NSManagedObjectContext?) {
super.init(entity: entity, insertInto: context)
}
init(dictionary: [String : AnyObject], context: NSManagedObjectContext) {
let entity = NSEntityDescription.entity(forEntityName: "Writer", in: context)!
super.init(entity: entity, insertInto: context)
id = ...
name = ...
picture = ...
publicationID = ...
language = ...
country = ...
lastArticle = ...
}
override func prepareForDeletion() {
if let _ = writerImage {
writerImage = nil
}
}
}