instance variables may not be placed in categories
Avoid Properties in Categories
Objective-C分类中是不允许增加成员变量的(Instance variables may not be placed in categories),我们可以通过运行时函数objc_setAssociatedObject
和 objc_getAssociatedObject
来让分类支持保存和获取一些数据,从而支持属性。
//EOCPerson+FriendShip.h
@interface EOCPerson (FriendShip)
@property (nonatomic, strong) NSArray *friends;
@end //EOCPerson+FriendShip.m
static const char* kFriendsPropertyKey = "kFriendsPropertyKey";
@implementation EOCPerson (Friendship)
- (NSArray*)friends {
return objc_getAssociatedObject(self, kFriendsPropertyKey);
} - (void)setFriends:(NSArray*)friends {
objc_setAssociatedObject(self, kFriendsPropertyKey, friends, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
@end
instance variables may not be placed in categories的更多相关文章
- swift的属性与变量- Stored Properties and Instance Variables
是一个概念 Stored Properties and Instance Variables If you have experience with Objective-C, you may know ...
- Instance Variables in ruby
Dogs have many shared characteristics, like the abilities to wag their tails and drink water from a ...
- Class and Instance Variables In Ruby
https://github.com/unixc3t/mydoc/blob/master/blog/caiv.md
- Effective Objective-C [上]
网上看到的 http://esoftmobile.com/2013/08/10/effective-objective-c/ 本文是针对<Effective Objective-C>一书的 ...
- Objective -C Categories
Objective -C Categories The dynamic runtime dispatch mechanism employed by Objective-C lets you add ...
- python class metaclass instance
>>> class CObj(object):... pass...>>> dir()['CObj', '__builtins__', '__doc__', '__ ...
- Class Methods & Variables
When calling an instance method like withdraw_securely, the syntax generally looks something like th ...
- Blocks and Variables
Blocks and Variables https://developer.apple.com/library/ios/documentation/cocoa/conceptual/Blocks/A ...
- 30天代码day4 Class vs. Instance
Class A blueprint defining the charactaristics and behaviors of an object of that class type. Class ...
随机推荐
- Jquery基础之事件操作
事件是用户操作时页面或页面加载时引发的用来完成javascript和HTML之间的交互操作.常见的元素点击事件.鼠标事件.键盘输入事件等,较传Javascript 相比JQuery增加并扩展了基本的事 ...
- Inno Setup使用上的几个问题 (转)
Inno Setup使用上的几个问题: [问题一:Inno Setup 执行REG文件代码?][Run]Filename: "{win}\regedit.exe";Paramete ...
- Android之用PopupWindow实现弹出listview形式菜单
Android 4.0之前的菜单使用非常广泛,但是在android4.0之后,很少使用先前的菜单样式了.那如何实现下图的样式了? 我们简单模拟一下. (1)屏蔽系统弹出的菜单: 1.首先创建至少一个系 ...
- haproxy 关闭ssl 3.0 加密
global log 127.0.0.1 local3 maxconn 65535 chroot /usr/local/haproxy uid 500 gid 500 daemon ssl-defau ...
- linux shell自定义函数(定义、返回值、变量作用域)介绍
http://www.jb51.net/article/33899.htm linux shell自定义函数(定义.返回值.变量作用域)介绍 linux shell 可以用户定义函数,然后在shell ...
- python内置函数(2)-递归与迭代
这篇文章简单介绍了迭代和递归的概念.两者的区别 什么是迭代: 迭代是重复反馈过程的活动,其目的通常是为了接近并达到所需的目标或结果.每一次对过程的重复被称为一次“迭代”,而每一次迭代得到的结果会被用来 ...
- Android 4.4 Kitkat 使能 USB adb 功能
背景 在 Linux-3.8 以后,Android 的内核分支,便去掉了 f_adb,改使用 USB function FS,在用户空间实现 USB adb 功能.这篇文章依据原作者的 Google+ ...
- ASP.NET打印EXCEl报表技术总结
序言:我们在做企业项目或者一些管理系统的时候往往会用到导出到excel报表这项功能,下面我介绍的是用windows自带的excel来打印 首先必须引入:Interop.Excel.dll.Intero ...
- MVC+simpleinjector 简单使用
一.首先添加NuGet包如下图
- c++到c#数据类型的转换
c++与c#的类型转换 分类:cSharp | 标签: c# system intptr char uint 2012-02-29 19:54 阅读(513)评论(0)编辑删除 //c++: ...