You have two instance variables.
Check it by writing one and reading the other.
You could also try to check it by getting the size of the instance, but
it doesn't work with Objective-C 2.0 since that run-time optimizes
allocations by rounding the object sizes:
----(instancevar.m)-------------------------------------------------------------
#import <Foundation/Foundation.h>
#import <objc/objc-runtime.h>
@interface DisplaySelfSize:NSObject
{
}
-(void)display;
@end
@interface Example1:DisplaySelfSize
{
int foo1;
}
@end
@interface Example2:DisplaySelfSize
{
int foo1;
int foo2;
}
@end
@implementation Example1
@end
@implementation Example2
@end
@implementation DisplaySelfSize
-(int)size{
return class_getInstanceSize([self class]);
}
-(void)display{
NSLog(@"size of an instance of %@ = %d\n",
[self class],[self size]);
}
@end
int main(){
[[[Example1 alloc] init] display];
[[[Example2 alloc] init] display];
return 0;
}
--------------------------------------------------------------------------------
$ cc -x objective-c instancevar.m -lobjc -framework Foundation -o instancevar && ./instancevar
2016-07-26 22:54:15.926 instancevar[70818:1934406] size of an instance of Example1 = 16
2016-07-26 22:54:15.927 instancevar[70818:1934406] size of an instance of Example2 = 16
$
> If they are indeed two distinct instance variables, does the
> object/instance look at it that way and treat them as such?
Yes.
> Also, can I assume that only the one with the leading underscore
> (_foo1) is backing the property?
Yes.