iOSの基礎となる学習日間の-11
はじめ-OC-Rutime記事
私は、iOSの開発者、午前基礎となるiOSの 30日間新人高度道路を。
ISAポインタ
- ランタイムを学ぶには、まず、このようなISAポインタとしての基礎となるいくつかの一般的に使用されるデータ構造を、理解しなければなりません
- arm64アーキテクチャ前に、ISAは、通常のポインタであり、記憶クラス、メタクラスオブジェクトのメモリアドレス
- 出発arm64アーキテクチャは共通ボディに、ISAのために最適化されている(連合)構造は、ビットフィールドは、より多くの情報を格納するために使用しました
ビットフィールド
- MJPerson.h
#import <Foundation/Foundation.h>
@interface MJPerson : NSObject
- (void)setTall:(BOOL)tall;
- (void)setRich:(BOOL)rich;
- (void)setHandsome:(BOOL)handsome;
- (BOOL)isTall;
- (BOOL)isRich;
- (BOOL)isHandsome;
@end
- MJPerson.m
#import "MJPerson.h"
#define MJTallMask (1<<0) 0b 0000 0001
#define MJRichMask (1<<1) 0b 0000 0010
#define MJHandsomeMask (1<<2) 0b 0000 0100
@interface MJPerson()
{
char _tallRichHansome;
}
@end
@implementation MJPerson
- (instancetype)init {
if (self = [super init]) {
_tallRichHansome = 0b00000100;
}
return self;
}
- (void)setTall:(BOOL)tall {
if (tall) {
_tallRichHansome = _tallRichHansome | MJTallMask;
} else {
_tallRichHansome = _tallRichHansome & ~MJTallMask;
}
}
- (BOOL)isTall {
return !!(_tallRichHansome & MJTallMask);
}
- (void)setRich:(BOOL)rich {
if (rich) {
_tallRichHansome |= MJRichMask;
} else {
_tallRichHansome &= ~MJRichMask;
}
}
- (BOOL)isRich {
return !!(_tallRichHansome & MJRichMask);
}
- (void)setHandsome:(BOOL)handsome {
if (handsome) {
_tallRichHansome |= MJHandsomeMask;
} else {
_tallRichHansome &= ~MJHandsomeMask;
}
}
- (BOOL)isHandsome {
return !!(_tallRichHansome & MJHandsomeMask);
}
@end
最適化した後、
- MJPerson.h
#import <Foundation/Foundation.h>
@interface MJPerson : NSObject
- (void)setTall:(BOOL)tall;
- (void)setRich:(BOOL)rich;
- (void)setHandsome:(BOOL)handsome;
- (BOOL)isTall;
- (BOOL)isRich;
- (BOOL)isHandsome;
@end
- MJPerson.m
#import "MJPerson.h"
@interface MJPerson()
{
// 位域
struct {
char tall : 1;
char rich : 1;
char handsome : 1;
} _tallRichHandsome; //0b 0000 0 handsome rich tall
}
@end
@implementation MJPerson
- (void)setTall:(BOOL)tall {
_tallRichHandsome.tall = tall;
}
- (BOOL)isTall {
return !!_tallRichHandsome.tall;
}
- (void)setRich:(BOOL)rich {
_tallRichHandsome.rich = rich;
}
- (BOOL)isRich {
return !!_tallRichHandsome.rich;
}
- (void)setHandsome:(BOOL)handsome {
_tallRichHandsome.handsome = handsome;
}
- (BOOL)isHandsome {
return !!_tallRichHandsome.handsome;
}
@end
isa_max
- arm64から、最適化されたISA、ISA&isa_max、オブジェクトを指しているアドレス値であり、特定のアドレスを格納するshift_cls33ビットであり、データストアにもっと何かを共通の構造体、構造体64を取りますの値