Given an entity with an attribute firstName, Core Data automatically generates firstName, setFirstName:, primitiveFirstName, and setPrimitiveFirstName.

  The primary use of primitive accessors is to prevent key-value observing notifications from being sent when you change a value.

  Sometimes you do not want such notifications sent because they have quite a bit of overhead. E.g. when importing large sets of data or when you use a transitory value to alter a persisted value.


  In my opinion,

  You could override the awakeFromInsert method to set a default value for this property;

  Every time you insert object into managedObjectContext,

  CoreData framework will call awakeFromInsert method automatically.

  And in this method,you should use primitive accssor to set the default value.

  For example,there is a property dueDate in the category's .h file,

  u can define primitiveDueDate property in the subclass of NSManagedObject.

  And add @dynamic primitiveDueDate in .m file.

   show u the code:

// a subclass of NSManagedObject

//.h file
@interface Task : NSManagedObject @property (nonatomic, strong) NSDate *primitiveDueDate; @end //.m file
@implementation Task @dynamic primitiveDueDate; - (void)awakeFromInsert{
[super awakeFromInsert]; NSDate *defaultDate = [NSDate dateWithTimeIntervalSinceNow:***]; // 3 days self.primitiveDueDate = defaultDate;
} @end // category file contains a property named dueDate @interface Task (CoreDataProperties) @property (nullable, nonatomic, retain) NSDate *dueDate; @end

References:

http://stackoverflow.com/questions/5509106/why-would-i-need-to-use-a-primitive-accessor-methods-in-a-core-data-project

http://stackoverflow.com/questions/7427373/what-are-the-primitive-accessors-for-in-core-data

Caution (infinite loop):

http://stackoverflow.com/questions/14150654/kvo-core-data-and-primitive-accessors

iOS CoreData primitive accessor的更多相关文章

  1. iOS CoreData技术学习资源汇总

    一.CoreData学习指引 1. 苹果官方:Core Data Programming Guide 什么是CoreData? 创建托管对象模型 初始化Core Data堆栈 提取对象 创建和修改自定 ...

  2. IOS CoreData 多表查询demo解析

    在IOS CoreData中,多表查询上相对来说,没有SQL直观,但CoreData的功能还是可以完成相关操作的. 下面使用CoreData进行关系数据库的表与表之间的关系演示.生成CoreData和 ...

  3. iOS CoreData (一) 增删改查

    代码地址如下:http://www.demodashi.com/demo/11041.html Core Data是iOS5之后才出现的一个框架,本质上是对SQLite的一个封装,它提供了对象-关系映 ...

  4. iOS CoreData (二) 版本升级和数据库迁移

    前言:最近ChinaDaily项目需要迭代一个新版本,在这个版本中CoreData数据库模型上有新增表.实体字段的增加,那么在用户覆盖安装程序时就必须要进行CoreData数据库的版本升级和旧数据迁移 ...

  5. IOS CoreData 多表查询(下)

    http://blog.csdn.net/fengsh998/article/details/8123392 在iOS CoreData中,多表查询上相对来说,没有SQL直观,但COREDATA的功能 ...

  6. iOS CoreData 介绍和使用(以及一些注意事项)

    iOS CoreData介绍和使用(以及一些注意事项) 最近花了一点时间整理了一下CoreData,对于经常使用SQLite的我来说,用这个真的有点用不惯,个人觉得实在是没发现什么亮点,不喜勿喷啊.不 ...

  7. iOS CoreData介绍和使用(以及一些注意事项)

    iOS CoreData介绍和使用(以及一些注意事项) 最近花了一点时间整理了一下CoreData,对于经常使用SQLite的我来说,用这个真的有点用不惯,个人觉得实在是没发现什么亮点,不喜勿喷啊.不 ...

  8. iOS - CoreData 数据库存储

    1.CoreData 数据库 CoreData 是 iOS SDK 里的一个很强大的框架,允许程序员以面向对象的方式储存和管理数据.使用 CoreData 框架,程序员可以很轻松有效地通过面向对象的接 ...

  9. iOS coreData问题

    iOS常见错误-CoreData: Cannot load NSManagedObjectModel.nil is an illegal URL parameter
这是因为在工程中CoreData的 ...

随机推荐

  1. Jquery attr("checked") 返回checked或undefined 获取选中失效解决方案

    jq1.6之前版本获取方式<input type='checkbox' id='cb'/> <script> //获取是否选中 var isChecked = $('#cb') ...

  2. 查询EBS中LOV的SQL语句

    1.帮助->关于:查找会话 SID : 507: 2.点一下LOV右边的三点,触发LOV事件: 3.运行如下代码段: DECLARE  l_sid NUMBER := :SID;BEGIN  F ...

  3. Json.net日期格式化

    1. 全局设置,可以在App_Global中配置 JsonSerializerSettings setting = new JsonSerializerSettings(); JsonConvert. ...

  4. maven实战(02)_坐标详解

    (一)  何为mave坐标 maven的世界中拥有数量非常巨大的构件,也就是平时用的一些jar,war等文件. maven定义了这样一组规则: 世界上任何一个构件都可以使用Maven坐标唯一标志,ma ...

  5. tcp 出现rst情况整理

    正常情况tcp四层握手关闭连接,rst基本都是异常情况,整理如下: 1. GFW 2. 对方端口未打开,发生在连接建立 如果对方sync_backlog满了的话,sync简单被丢弃,表现为超时,而不会 ...

  6. Gnome_Terminal

    快捷键 ctrl shift m 我自定义的快捷键,可以给终端命名 ctrl shift t 新建标签页,并且目录为当前目录 ctrl shift pageup 标签页往前移 ctrl shift p ...

  7. sublime一些快捷键

    语法: 后代:> 缩写:nav>ul>li <nav> <ul> <li></li> </ul> </nav> ...

  8. git整理

    git图形客户端:SourceTree bash: 先初始化: git init 添加远程仓库: git remote add sae https://git.sinacloud.com/newapp

  9. js学习进阶-页面覆盖

    页面覆盖以显示一条信息,照片或者常见的登录,广告, 实例: <!DOCTYPE html> <html> <head> <meta charset=" ...

  10. 【转载】SSM框架整合

    http://blog.csdn.net/gebitan505/article/details/44455235/ 1.基本概念 1.1.Spring Spring是一个开源框架,Spring是于20 ...