OC与Swift混合开发
2016-09-19 本文已影响34人
sunshinesuns
在OC文件中调用Swift相关方法时需设置
6C205088-766F-41A3-9FD6-EF628E62C583.png其中值为"项目名称-Swift.h",并在相关文件中导入#import "ObjecAndSwift-Swift.h"
Person类
@interface Person : NSObject
- (void)sayHi:(NSString *)name;
@end
@implementation Person
- (void)sayHi:(NSString *)name{
NSLog(@"sayhi %@",name);
}
@end
Swift方法,调用OC
public class Student: NSObject {
func sayHello(name:String) -> Void {
print("sayhello to \(name)")
let person = Person()
person.sayHi("lisi")
}
}
在OC中调用Swift
Student *sty = [[Student alloc]init];
[sty sayHello:@"PHP"];