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 ...
随机推荐
- Firebug Command Line
http://michaelsync.net/2007/09/15/firebug-tutorial-commandline-api
- 使用myeclipse生成的HibernateSessionFactory的合理性
作为简单的一个单件模式, getSessionFactory()函数返回null是一个不合理的决定,可以返回一个没有初始化的SessionFactory对象,但是返回null就和这种模式的语意有冲突了 ...
- poj 3233 Matrix Power Series
A为一个n*n的矩阵,求A+A^2+A^3+...+A^n Sk = A + A2 + A3 + - + Ak =(1+Ak/2)*(A + A2 + A3 + - + Ak/2 )+{ ...
- 浅谈C语言中的强符号、弱符号、强引用和弱引用
摘自http://www.jb51.net/article/56924.htm 浅谈C语言中的强符号.弱符号.强引用和弱引用 投稿:hebedich 字体:[增加 减小] 类型:转载 时间:2014- ...
- ubuntu 下node 环境的安装
1. 安装nodejs sudo apt-get install nodejs 注意:包名是nodejs 2. 建立node软连接 #找到nodejs位置 which nodejs # /usr/bi ...
- Pasha and Phone(思维)
Pasha and Phone time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- UIPageViewController-浅析
一.UIPageViewController概念 控件为我们提供了一种像翻书效果的一种控件.我们可以通过使用UIPageViewController控件,来完成类似图书一样的翻页控制方式. 二 ...
- 【线段树求最靠前】【HDU2795】【Billboard】
题意: 有一个H*W的广告牌,当插入一个广告时(1*Wi),问最靠前的插入方式是什么 新生赛有个类似的题目,可惜当时居然没水过去. 果断用线段树做 以H为线段 建树,存[l,r]中最大的宽度,因为区间 ...
- chrome插件 postman 可以调用restful服务
chrome插件 postman 可以调用restful服务
- asp.net 树形控件 $.fn.zTree.init
在网页中通过jquery脚本来构筑树形控件将是一个不错的选择,比如有一个文本框,当鼠标点击的时候,像弹出一个下拉框一样弹出一个树形控件,这似乎是一个不错的控制.下面主要讲讲这种树形控件的实现.为了能使 ...