Skip to content

Commit

Permalink
fallback for synthesized _ivars
Browse files Browse the repository at this point in the history
  • Loading branch information
ksjogo committed Jul 15, 2016
1 parent 68e1e3c commit 7b1bd28
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions objc/NSObject+Nu.m
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,13 @@ - (id) handleUnknownMessage:(id) message withContext:(NSMutableDictionary *) con
- (id) valueForIvar:(NSString *) name
{
Ivar v = class_getInstanceVariable([self class], [name cStringUsingEncoding:NSUTF8StringEncoding]);
if (!v) {

if (!v) {
//check if a _variable was synthesized
v = class_getInstanceVariable([self class], [[@"_" stringByAppendingString:name] cStringUsingEncoding:NSUTF8StringEncoding]);
}

if (!v) {
// look for sparse ivar storage
NSMutableDictionary *sparseIvars = [self associatedObjectForKey:@"__nuivars"];
if (sparseIvars) {
Expand All @@ -402,7 +408,13 @@ - (id) valueForIvar:(NSString *) name
- (BOOL) hasValueForIvar:(NSString *) name
{
Ivar v = class_getInstanceVariable([self class], [name cStringUsingEncoding:NSUTF8StringEncoding]);
if (!v) {

if (!v) {
//check if a _variable was synthesized
v = class_getInstanceVariable([self class], [[@"_" stringByAppendingString:name] cStringUsingEncoding:NSUTF8StringEncoding]);
}

if (!v) {
// look for sparse ivar storage
NSMutableDictionary *sparseIvars = [self associatedObjectForKey:@"__nuivars"];
if (sparseIvars) {
Expand All @@ -425,7 +437,11 @@ - (BOOL) hasValueForIvar:(NSString *) name
- (void) setValue:(id) value forIvar:(NSString *)name
{
Ivar v = class_getInstanceVariable([self class], [name cStringUsingEncoding:NSUTF8StringEncoding]);
if (!v) {
if (!v) {
//check if a _variable was synthesized
v = class_getInstanceVariable([self class], [[@"_" stringByAppendingString:name] cStringUsingEncoding:NSUTF8StringEncoding]);
}
if (!v) {
NSMutableDictionary *sparseIvars = [self associatedObjectForKey:@"__nuivars"];
if (!sparseIvars) {
sparseIvars = [[[NSMutableDictionary alloc] init] autorelease];
Expand Down Expand Up @@ -508,7 +524,11 @@ + (NSArray *) instanceVariableNames
+ (NSString *) signatureForIvar:(NSString *)name
{
Ivar v = class_getInstanceVariable([self class], [name cStringUsingEncoding:NSUTF8StringEncoding]);
return [NSString stringWithCString:ivar_getTypeEncoding(v) encoding:NSUTF8StringEncoding];
if (!v) {
//check if a _variable was synthesized
v = class_getInstanceVariable([self class], [[@"_" stringByAppendingString:name] cStringUsingEncoding:NSUTF8StringEncoding]);
}
return [NSString stringWithCString:ivar_getTypeEncoding(v) encoding:NSUTF8StringEncoding];
}

+ (id) inheritedByClass:(NuClass *) newClass
Expand Down

0 comments on commit 7b1bd28

Please sign in to comment.