Movie App 学习笔记:CoreData Object Model Generation

源自 NEW- CoreData for Swift Development (Swift 4.2 & iOS 12)

Codegen: Class Definition

Class Definition automatically creates the NSManagedObject subclass behind the scene, including the attributes information.

Codegen: Category/Extension

Category/Extension allow flexibility of using the class file to handle custom function, whereas the properties file is still created and loaded behind the scene.

在使用这种模式的情况下,添加类的自定义函数时,需要手工创建该类的(Movie)的 extension 文件 Movie+CoreDataClass.swift,手动新建该类,如下截图所示。

如果忘记了 @objc(Movie) 会报错 An NSManagedObject of class 'Movie.Movie' must have a valid NSEntityDescription



Tagged as:


Fill in your details below or click an icon to log in: 徽标

You are commenting using your account. Log Out /  更改 )

Google+ photo

You are commenting using your Google+ account. Log Out /  更改 )

Twitter picture

You are commenting using your Twitter account. Log Out /  更改 )

Facebook photo

You are commenting using your Facebook account. Log Out /  更改 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.