Runtime 自动化归档
Runtime的使用
(id)initWithCoder:(NSCoder *)decoder
{
if (self = [super init]) {
unsigned int count = ;
Ivar *ivars = class_copyIvarList([self class], &count); for (int i = ; i<count; i++) {
Ivar ivar = ivars[i]; // 获取成员变量
const char *name = ivar_getName(ivar); // 归档
NSString *key = [NSString stringWithUTF8String:name];
id value = [decoder decodeObjectForKey:key]; // 设置
[self setValue:value forKey:key];
} free(ivars);
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)encoder
{ unsigned int count = ;
Ivar *ivars = class_copyIvarList([self class], &count); for (int i = ; i<count; i++) { Ivar ivar = ivars[i]; //获取成员变量
const char *name = ivar_getName(ivar); // 归档
NSString *key = [NSString stringWithUTF8String:name];
id value = [self valueForKey:key];
[encoder encodeObject:value forKey:key];
} free(ivars);
}
Runtime 自动化归档的更多相关文章
- runtime之归档和解档
IOS开发之NSCoding协议(使用runtime)近期学习IOS的runtime库,然后看到之前写的NSCoding协议有点复杂,如果属性少还好,如果100多个属性,则会显得麻烦.下面使用常规方式 ...
- 用runtime封装归档(encoding)
runtime一套比较基层的c语言的API(库) 归档(OC对象-->字典—>2进制—>写入沙盒 || 目的.数据持久化) #import <UIKit/UIKit.h&g ...
- iOS--通过runtime完成归档,反归档
通过runtime,不管模型有多少属性,通过几句代码就能完成. 假设person类有N多个属性而是(这里随便写3个) .h #import <Foundation/Foundation.h> ...
- 使用runtime完成解档归档
简单的创建一个Person对象,并声明几个属性 @interface Person : NSObject<NSCoding> // 归档问题 必须遵守该协议 /** */ @propert ...
- iOS 模式详解—「runtime面试、工作」看我就 🐒 了 ^_^.
引导 Copyright © PBwaterln Unauthorized shall not be *copy reprinted* . 对于从事 iOS 开发人员来说,所有的人都会答出「runti ...
- RunTime总结:
oc动态性, 运行时将代码转化为runtime的C代码 RunTime运行流程: 生成对应objc_msgSend方法 isa指针查看当前类有没有这个方法, 之后寻找父类, 每个方法SEL(方法选择器 ...
- runtime运行机制方法学习
runtime这玩意第一次听说时都不知道是什么,经过了解后才知道它就是oc动态语言的机制,没有它那oc就不能称为动态语言.在之前可能大家对runtime了解都不深,随着编程技能的日益加深和需要,大家开 ...
- Runtime -----那些被忽略的技能
有人说现在的程序员都被惯坏了,尤其使用一些面向对象的语言开发的时候,只是简单的调用一些系统封装好的接口或者是调用一些“便利的”第三方,对于一个程序的真正实现有了解吗???又有多少了解呢 ...
- iOS之RunTime浅谈
首先说一下什么是runtime:RunTime简称运行时.就是系统在运行的时候的一些机制,其中最主要的是消息机制.对于C语言,函数的调用 在编译的时候会决定调用哪个函数( C语言的函数调用请看这里 ) ...
随机推荐
- 36. Valid Sudoku 判断九九有效的数独
[抄题]: Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according ...
- [leetcode]1. Two Sum两数之和
Given an array of integers, return indices of the two numbers such that they add up to a specific t ...
- Linux下查看磁盘挂载的几种方法
Linux下查看磁盘挂载的几种方法 第一种方法:df命令 # df -hT Filesystem Type Size Used Avail Use% Mounted on devtmpfs devtm ...
- 31.Mysql复制
31.Mysql复制复制是指将主数据库的DDL和DML操作通过二进制日志传到从数据库上,然后在从数据库上对重做日志,从而使从库与主库保持同步.Mysql支持一台主库同时向多台从库复制,从库也可以作为其 ...
- ubuntu,day1基础命令,shutdown,man,touch,rm,mv,cp,stat,locale,apt,date,tzselect,cal,快捷方式,echo,查看文件
基本设置命令 1,shutdown 命令, shutdown -r now # 现在立即重启 shutdown -r + # 三分钟后重启 shutdown -r : #在12:12时将重启计算机 s ...
- ipcam
ipcam也叫ip network camera,就是基于internet protocol的网络摄像机,同普通摄像头或者网眼的主要区别是ipcam实际上是一台视频服务器和摄像头的集成.ipcam只要 ...
- JVM 字节码(四)静态方法、构造代码、this 以及 synchronized 关键字
JVM 字节码(四)静态方法.构造代码.this 以及 synchronized 关键字 一.静态代码 public class ByteCodeStatic { private static fin ...
- 用python语言算π值并且带有进度条
用python算圆周率π 1.准备第三方库pip 打开cmd 输入代码:pip install requests ,随后就会成功 因为小编已经安装好了,所以就不把图截出来了 2.利用马青公式求π ...
- To handling editor letter
一般崔稿信写法: Dear Editor: Sorry for disturbing you. We’re not sure if it is the right time to contact yo ...
- qhfl-3 Course模块
课程模块,包括免费课程以及专题课程两个,主要是课程的展示,点击课程进入课程详细页面 根据功能设计表结构 为了方便,每张表在数据库中添加了中文名 from django.db import models ...