iOS CoreData primitive accessor
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/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的更多相关文章
- iOS CoreData技术学习资源汇总
一.CoreData学习指引 1. 苹果官方:Core Data Programming Guide 什么是CoreData? 创建托管对象模型 初始化Core Data堆栈 提取对象 创建和修改自定 ...
- IOS CoreData 多表查询demo解析
在IOS CoreData中,多表查询上相对来说,没有SQL直观,但CoreData的功能还是可以完成相关操作的. 下面使用CoreData进行关系数据库的表与表之间的关系演示.生成CoreData和 ...
- iOS CoreData (一) 增删改查
代码地址如下:http://www.demodashi.com/demo/11041.html Core Data是iOS5之后才出现的一个框架,本质上是对SQLite的一个封装,它提供了对象-关系映 ...
- iOS CoreData (二) 版本升级和数据库迁移
前言:最近ChinaDaily项目需要迭代一个新版本,在这个版本中CoreData数据库模型上有新增表.实体字段的增加,那么在用户覆盖安装程序时就必须要进行CoreData数据库的版本升级和旧数据迁移 ...
- IOS CoreData 多表查询(下)
http://blog.csdn.net/fengsh998/article/details/8123392 在iOS CoreData中,多表查询上相对来说,没有SQL直观,但COREDATA的功能 ...
- iOS CoreData 介绍和使用(以及一些注意事项)
iOS CoreData介绍和使用(以及一些注意事项) 最近花了一点时间整理了一下CoreData,对于经常使用SQLite的我来说,用这个真的有点用不惯,个人觉得实在是没发现什么亮点,不喜勿喷啊.不 ...
- iOS CoreData介绍和使用(以及一些注意事项)
iOS CoreData介绍和使用(以及一些注意事项) 最近花了一点时间整理了一下CoreData,对于经常使用SQLite的我来说,用这个真的有点用不惯,个人觉得实在是没发现什么亮点,不喜勿喷啊.不 ...
- iOS - CoreData 数据库存储
1.CoreData 数据库 CoreData 是 iOS SDK 里的一个很强大的框架,允许程序员以面向对象的方式储存和管理数据.使用 CoreData 框架,程序员可以很轻松有效地通过面向对象的接 ...
- iOS coreData问题
iOS常见错误-CoreData: Cannot load NSManagedObjectModel.nil is an illegal URL parameter 这是因为在工程中CoreData的 ...
随机推荐
- jquery.nicescroll.js可全屏可改滚动条颜色的滚动条插件-推荐
有一款很棒的插件 http://www.ijquery.cn/?p=666
- Eclipse的快捷键
Ctrl+Shift+L调出eclipse的所有快捷键 不定期更新2016#8#19 如何配置快捷键:windown-preferences-General-key 一些操作 Ctrl+D 删除 ...
- Decode Ways
https://leetcode.com/problems/decode-ways/ A message containing letters from A-Z is being encoded to ...
- Maven pom.xml 元素配置说明(一)
部分来源: Maven中 dependencies 节点和 dependencyManagement 节点的区别 dependencies与dependencyManagement的区别 maven ...
- linQ学习笔记之三高级语句
linq语句查询执行的时机 第一步获取数据源 int [] obejct = new int[]{1,2,3,4,5,6,7,8,9} 第二步定义查询 var even = numbers.where ...
- bzoj4237 稻草人
我是萌萌的传送门 题意不难理解吧-- 一开始看到这道题的时候lrd告诉我这题要分治,还给我讲了讲分治要怎么写,好像是CDQ+树状数组来着--(好吧我已经忘了--)然而我第一眼看完题之后的思路是数据结构 ...
- mysql 基础
(1)插入多条数据 INSERT INTO users(name, age) VALUES('姚明', 25), ('比尔.盖茨', 50), ('火星人', 600); (2)将查询出来的字段插入其 ...
- python升级
一开始有这个需求,是因为用 YaH3C 替代 iNode 进行校园网认证时,一直编译错误,提示找不到 Python 的某个模块,百度了一下,此模块是在 Python2.7 以上才有的,但是系统的自带的 ...
- IE8下String的Trim()方法失效的解决方案
简洁方便 用jquery的trim()方法,$.trim(str)就可以了.
- linux 下查看cpu位数 内核等参数命令(转)
# uname -a Linux euis1 2.6.9-55.ELsmp #1 SMP Fri Apr 20 17:03:35 EDT 2007 i686 i686 i386 GNU/Linux ( ...