inheritance - Calling a Swift Method from Objective C class -
i want create inheritance between swift class , objective-c class.
the swift class creates person, objective c class creates pupil (who person)
my swift person is:
import foundation class person { var age: int var height: float init(){ self.age = 22 self.heigh =1.80 } init(age:int, height:float){ self.age=age self.height=height } } the objective-c pupil is:
student.h:
#import <foundation/foundation.h> #import "praktikum2a-swift.h" @interface pupil : person @property (nonatomic) int studentid; -(void)setstudentid:(int)stdid; @end student.m:
#import <foundation/foundation.h> #import "praktikum2a-swift.h" #import "student.h" @implementation pupil -(id)init{ homecoming [self initwithstudentid:1337]; } -(id)initwithstudentid:(int)stdid{ self=[super init]; if(self){ [self setstudentid:stdid]; } } @end and main:
#import <foundation/foundation.h> #import "student.h" int main(int argc, const char * argv[]) { @autoreleasepool { pupil *hugo = [[student alloc] init]; [hugo setage: 22 setheight: 1.80]; nslog(@"hello, world!"); } homecoming 0; } the project , bundle name praktikum2a
basically can't figure out, why pupil isn't person... =/
it says on page: https://developer.apple.com/library/ios/documentation/swift/conceptual/buildingcocoaapps/mixandmatch.html#//apple_ref/doc/uid/tp40014216-ch10-xid_77
note cannot subclass swift class in objective-c
objective-c inheritance swift
No comments:
Post a Comment