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 ...
随机推荐
- 提取肤色信息原理及操作——opencv
网上也有很多的资料,讲述怎么提取肤色的,大致有5种方法.这几种方法转载http://blog.csdn.net/augusdi/article/details/8865275 第一种:RGB colo ...
- Oracle EBS-SQL (INV-12):检查待定事物处理1.sql
/*未加工物料*/ update inv.mtl_material_transactions_temp set process_flag='Y', LOCK_FLAG='N', TRANSACTION ...
- 用 for/in 在 Java 5.0 中增强循环
这个方便的构造提供了什么?什么时候适用于代码? Brett McLaughlin (brett@newInstance.com), 作者/编辑, O'Reilly Media, Inc. 简介: fo ...
- 处理编译错误"0" is an invalid value for the "DebugInformation" parameter of the "DCC"
在编译“MustangpeakCommonLib-master.zip”时,遇到了这个问题.网上搜了一下: 处理编译错误"0" is an invalid value for the "DebugIn ...
- linux shell命令行下操作mysql 删除mysql指定数据库下的所有表--亲测成功百分百测试通过--绝对可靠
1,在shell提示符下查看mysql指定数据库下的表等数据
- SqlCommand.ExecuteScalar 方法
本文来自:http://msdn.microsoft.com/zh-cn/library/system.data.sqlclient.sqlcommand.executescalar(v=vs.100 ...
- 滚动栏范围位置函数(SetScrollRange、SetScrollPos、GetScrollRange、GetScrollPos)
滚动栏的范围是一对整数,默认情况下,滚动栏的范围是0~100. SetScrollRange(hwnd,iBar,iMin,iMax,bRedraw)这里的iBar參数要么是SB_VERT,要么是SB ...
- mysql基础:mysql与C结合实例
一个简单的mysql与C的交互,使用了一些mysql的C API! 老鸟掠过,新手能够看看! /****************************************** 本文件学习mysq ...
- 【二分+最大团】【HDU3585】【maximum shortest distance】
题目大意 在N个点钟 选出K个点 使得这K个点间的最小距离最大 二分距离,然后如果两点间距离小于它的边当做不存在,求出最大团,如果最大团>=K,向上缩小区间 < K , 向下缩小区间 ...
- linode最新试用(购买)流程
最新linode官网www.linode.com可以免费试用7天,但是需要你的身份认证 第一步:注册一个linode账号email填写国内的163.126.qq邮箱是不能认证的,这里可以填写gmail ...