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的 ...
随机推荐
- LPC43xx系列使用IAP的注意事项
LPC43xx系列使用IAP的注意事项 Tags: LPC43xx IAP 单片机 LPC43xx IAP函数的调用 一般MCU的IAP是,厂商固化一段代码在芯片的某个区域,然后告诉你这个代码的入口地 ...
- Android Studio Error:CreateProcess error=216
Error:CreateProcess error=216, This version of %1 is not compatible with the version of Windows you' ...
- dubbo实践
最近公司准备重构内部服务模块,准备使用dubbo,故研究一下. 官方文档:http://alibaba.github.io/dubbo-doc-static/Home-zh.htm 1. 用maven ...
- The Safe Navigation Operator (&.) in Ruby
The most interesting addition to Ruby 2.3.0 is the Safe Navigation Operator(&.). A similar opera ...
- vim的使用与配置
vim的简单使用 Content 三种模式 光标移动 查找与替换 删除.复制和粘贴 命令行 块选择 多文件编辑 多窗口显示 中文编码问题 语系转换和 三种模式 vim可以分为一般模式.编辑模式和命令行 ...
- jquery.validate不用submit而用js提交的例子
$("#form").validate(); $("#btn).click(function(){ if($("#form").valid()){ $ ...
- Mac 安装配置rz、sz
在Iterm2中修改配置: 安装lrzsz brew install lrzsz 下载iterm2-zmodem cd /usr/local/bin sudo wget https://raw.git ...
- Unity3D 解决用Unity导出的Android工程在6.0及以上设备会弹出一串权限对话框的问题
解决用Unity导出的Android工程在6.0及以上设备会弹出一串权限对话框的问题 <meta-data android:name="unityplayer.SkipPermissi ...
- Unity3D访问Android系统目录
file:///sdcard/Movies/3D/互动.mp4file:///storage/emulated/0/Movies/3D/互动.mp4/storage/emulated/0/Movies ...
- angular $http 与form表单的select-->refine
<!DOCTYPE html> <html ng-app="a2_15"> <head> <meta http-equiv="C ...