Created
April 21, 2024 15:08
-
-
Save pookjw/f6048843059c31a804c88c146c184b74 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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