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. R语言画云字图

    install.packages('wordcloud') library(wordcloud) colors=c('red','blue','green','yellow','purple') da ...

  2. 移动端web开发的一些知识点

    整理一下自己平时移动端web开发中遇到的问题,也参考一下前辈的一些总结 1.最常见的要数1像素边框了 因为Retine屏的分辨率始终是普通屏幕的2倍,1px的边框在dpr=2的retina屏下会显示成 ...

  3. 学习 opencv---(5) 创建Trackbar(活动条) &图像对比度,亮度值调整

    学习如何在opencv 中用trackbar 函数创建和使用 轨迹条,以及图像对比度,亮度值的动态调整 一.OpenCV中轨迹条(Trackbar)的创建和使用 [1]创建轨迹条-----create ...

  4. java大并发数据保存方案

    做了几年.net,如今终于要做java了. 需求: 线下终端会定时上传gps位置到服务端,服务端收到数据保存到mysql数据库,当线下终端过多时,问题出现了,首当其冲的是数据库连接池经常会崩溃,单个t ...

  5. SVProgressHUD

    原文:http://cht005288201307234627.iteye.com/blog/1927961 SVProgressHUD和MBProgressHUD效果差不多,不过不需要使用协议,同时 ...

  6. C语言移位算符">>"

    右移算符>>是将二进制数的每一位右移.如:a=32,a>>2,就是将32的二进制数100000每一个二进制位向右移动两位.得到的是二进制数1000,也就是8. #include ...

  7. JavaScript中的面向对象

    //简单的面向对象 function 构造函数(){ this.属性; } //写在构造函数里面的属性一般为公共属性,或者通过传值进行改变. 构造函数.原型.方法 = function(){}; // ...

  8. 在 Angularjs 中 ui-sref 和 $state.go 如何传递参数

    1 ui-sref.$state.go 的区别 ui-sref 一般使用在 <a>...</a>: <a ui-sref="message-list" ...

  9. Dcloud HTML5 监听蓝牙设备 调用 原生安卓实现

    最近一直搞Dcloud ,这是HTML5版本的开发,打包时候,可以打包成 apk 和ipa 分别运行在安卓和ios 机器上面, 但是这里面的资料很少,遇到问题,之后只能自己钻研总结, 现在有这么一个需 ...

  10. Linux Memcached安装以及PHP扩展安装

    一:安装libevent 由于memcached安装时,需要使用libevent类库,所以先安装libevent 1.下载 #wget   http://www.monkey.org/~provos/ ...