Ram*_*ing 17 frameworks objective-c swift2
我有一个(OS X)Objective-C框架,我想添加一些Swift扩展,我正在使用Xcode7ß6来处理这个问题.框架中有一个类(我们称之为"Sample")在文件"Sample.h"和"Sample.m"中实现."Sample.h"包含:
#import <Foundation/Foundation.h>
@interface Sample : NSObject
@property int x;
@end
Run Code Online (Sandbox Code Playgroud)
..和"Sample.m"包含:
#import "Sample.h"
@implementation Sample
- (instancetype) init {
if ((self = [super init]) == nil) return nil;
self.x = 99;
return self;
}
@end
Run Code Online (Sandbox Code Playgroud)
我在框架中添加了"Sample.swift",其中包含:
import Foundation
extension Sample {
func PrettyPrint () {
print("\(x)")
}
}
Run Code Online (Sandbox Code Playgroud)
这显然是我想在更大的上下文中做的简单版本,在这里我想使用Swift文件通过添加"PrettyPrint"函数来扩展"Sample".
..框架构建没有错误,但框架功能"PrettyPrint"对于调用应用程序是不可见的.调用框架的应用程序代码如:
import Foundation
import TestKit
let sample = Sample()
sample.PrettyPrint()
Run Code Online (Sandbox Code Playgroud)
使用"sample.PrettyPrint()"失败:"Sample"类型的值没有成员'PrettyPrint'
为什么这会失败?并且是否可以做的工作?
额外信息:如果我从框架中删除文件"Sample.swift"并将其放入调用框架的应用程序,则"Sample"类成功扩展并且"sample.PrettyPrint()"按预期工作(打印" 99" ).
tie*_*tie 13
您是否尝试将扩展和功能公开?
public extension Sample {
public func PrettyPrint () {
print("\(x)")
}
}
Run Code Online (Sandbox Code Playgroud)