Nav Link On

iPhone Dev Forums > General Development > SDK Coding Help > Help with @property in two classes

Reply

 

LinkBack Thread Tools Display Modes
Old 02-08-2010, 11:33 AM   #1 (permalink)
Junior Member
Default Avatar
 
Join Date: Feb 2010
Posts: 2
Default Help with @property in two classes

Can some one help me with "@property"? I have two classes A and B , class A inherit NSObject and class B inherit class A, both classes A and B has property, now when i use setter it is fine but i got error at run time when i use getter.

-----------------------------
Code:

You must Login or Register to view and contribute code! This is done to increase participation in helping one another out, if you have been helped please pass on the favor.

@interface A:NSObject
{
   int ageA;
}

@property int ageA;
@end

@implement A
synthesize ageA;
@end

@interface B:A
{
   int ageB;
}

@property int ageB;
@end

@implement B
synthesize ageB;
@end

--------------------------
B *instance=[[B alloc] init];

//here are fine
[instance setAgeA:97];
[instance setAgeB:200];

//here get error say Bad access
NSLog(@"A age is: %d", instance.ageA);
NSLog(@"B age is: %d", instance.ageB);
Why i get error, can i use two classes that have inheritance with @property or i can just use property for only one class.
tomneo2004 is offline   Reply With Quote
Old 02-09-2010, 02:25 AM   #2 (permalink)
Junior Member
Default Avatar
 
Join Date: Feb 2010
Posts: 2
Default

can some one help please
tomneo2004 is offline   Reply With Quote
Old 02-09-2010, 12:08 PM   #3 (permalink)
Senior Member
 
hello24's Avatar
 
Join Date: Jan 2010
Location: London, UK
Posts: 126
Send a message via Skype™ to hello24
Default

You'll need to use:
@synthesize ageA;

Notice the @ sign before synthesize!
hello24 is offline   Reply With Quote
Reply

iPhone Dev Forums > General Development > SDK Coding Help


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0 RC1