【问题标题】:Calling a Swift Method from Objective C class从 Objective C 类调用 Swift 方法
【发布时间】:2014-10-20 23:57:01
【问题描述】:

我想在一个swift类和一个objective-c类之间创建一个继承。

swift类创建一个人,objective c类创建一个学生(也是一个人)

我的快人是:

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
}
}

Objective-c 学生是:

学生.h:

#import <Foundation/Foundation.h>
#import "Praktikum2a-Swift.h"

@interface student : person

@property (nonatomic) int studentID;

-(void)setStudentID:(int)stdID;

@end

学生.m:

#import <Foundation/Foundation.h>
#import "Praktikum2a-Swift.h"
#import "student.h"

@implementation student

-(id)init{
    return [self initWithStudentID:1337];
}

-(id)initWithStudentID:(int)stdID{
    self=[super init];
    if(self){
        [self setStudentID:stdID];
    }
}

@end

还有主要的:

#import <Foundation/Foundation.h>
#import "student.h"

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        student *hugo = [[student alloc] init];

        [hugo setAge: 22 setHeight: 1.80];


        NSLog(@"Hello, World!");
    }
    return 0;
}

项目和包名称是 Praktikum2a

基本上我想不通,为什么我的学生不是人... =/

【问题讨论】:

标签: objective-c inheritance swift


【解决方案1】:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-19
    • 2015-03-28
    • 1970-01-01
    • 2012-02-09
    相关资源
    最近更新 更多