Accessing Subclass variables Objective-C -


new objective-c/ios , can't figure out how access subclasses variable. i've created person class contains following code:

@interface person : nsobject  @property nsstring *firstname; 

and i've initiated viewcontroller , works fine.

next right clicked on person class, , created sub class of person , added this:

#import "person.h"  @interface student : person  @property nsinteger studentid;  @end 

in viewcontroller;

person *person = [[person alloc] init];  person.firstname = @"name"; person.lastname = @"lastname"; 

all works fine, can't figure out how access subclass student's variable studentid?

i've tried initialising subclass doesnt seem work.

cheers

you can't person. initialized person, not student. subclasses can access parent properties, not other way around. can this:

student *person = [[student alloc] init];  person.firstname = @"name"; person.lastname = @"lastname"; person.sudentid = 123; 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -