LoginSignup
4
4

More than 5 years have passed since last update.

サブクラスごとに個別の値を持てる(クラス)変数

Last updated at Posted at 2014-10-28
#import <objc/runtime.h>
@implementation Hoge
+ (void)setName:(NSString *)name
{
    objc_setAssociatedObject(self, "name", name, OBJC_ASSOCIATION_COPY);
}

+ (NSString *)name
{
    id name = objc_getAssociatedObject(self, "name");
    return [name copy];
}
@end

selfはクラスオブジェクトなのでクラスごとに違う値がもてます。

4
4
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4