如股票oc要调用swift里面的代码 须要包含固定这个头文件html
项目名称 LiqunSwiftDemo-Swift.h前端
#ProjectName#-Swift.hswift
固定的写法后端
swift 目的 是取代oc 可是 不会彻底取代 只是前端的替换ide
LiqunSwiftDemo-Swift 点进去 能够看到 全部的swift代码 都产生了 对应的一个 oc的类post
也就是 编译过程当中 swift 先转换成 oc代码 再由oc代码转换成 c代码 (swift 在oc 之上 编译器前端的语法的转换 不涉及到编译器后端的转换)spa
1, #import <LiqunSwiftDemo-Swift.h>code
2, 写一个swift 类htm
import Foundation class TestSwift : NSObject { override init() {// print("in init") } func someFunc(){ print("in someFunc") } func getArrayByValue(v1:String ,v2:String) -> NSArray{ return [v1 , v2] } }
在oc 中调用blog
TestSwift *ts = [[TestSwift alloc]init];
[ts someFunc];
NSArray * arr = [ts getArrayByValue:@"今每天气" v2:@"---没有雾霾"];
for(NSString *str in arr){
NSLog(@"str is %@",str);
}
//结果
in init
in someFunc
2016-01-15 15:39:27.586 LiqunSwiftDemo[1776:117383] str is 今每天气
2016-01-15 15:39:31.346 LiqunSwiftDemo[1776:117383] str is ---没有雾霾