Skip to content

Instantly share code, notes, and snippets.

@pookjw
Created April 21, 2024 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pookjw/f6048843059c31a804c88c146c184b74 to your computer and use it in GitHub Desktop.
Save pookjw/f6048843059c31a804c88c146c184b74 to your computer and use it in GitHub Desktop.
#import <Foundation/Foundation.h>
#pragma mark - MyDescriptor
__attribute__((objc_direct_members))
@interface MyDescriptor : NSObject {
@package NSInteger _index;
}
- (BOOL)direct_isEqual:(MyDescriptor *)other;
@end
@implementation MyDescriptor
- (BOOL)direct_isEqual:(MyDescriptor *)other {
if (self == other) {
return YES;
} else {
return _index == other->_index;
}
}
@end
#pragma mark - MyController
__attribute__((objc_direct_members))
@interface MyController : NSObject {
@private MyDescriptor *_descriptor;
}
- (BOOL)updateLayoutWithDescriptor:(MyDescriptor *)descriptor;
@end
@implementation MyController
- (BOOL)updateLayoutWithDescriptor:(MyDescriptor *)descriptor {
if ([_descriptor direct_isEqual:descriptor]) {
return NO;
}
_descriptor = descriptor;
[NSThread sleepForTimeInterval:0.1];
return YES;
}
@end
#pragma mark - main
int main(int argc, const char * argv[]) {
@autoreleasepool {
MyController *controller = [MyController new];
MyDescriptor *descriptor = [MyDescriptor new];
descriptor->_index = 3;
assert([controller updateLayoutWithDescriptor:descriptor]);
descriptor->_index = 4;
assert([controller updateLayoutWithDescriptor:descriptor]); // hit program assert
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment