【发布时间】:2015-04-13 10:46:28
【问题描述】:
当我尝试在 Swift 中转换 2 个函数时遇到一些错误!
ObjC
@property (nonatomic, strong) NSMutableDictionary *textureCache;
- (instancetype)init {
if (self = [super init])
{
self.textureCache = [NSMutableDictionary dictionary];
}
return self;
}
- (SKTexture *)textureNamed:(NSString *)textureName {
return _textureCache[textureName];
}
斯威夫特
var textureCache: NSMutableDictionary?
public func init() -> Self {
return textureCache = NSMutableDictionary()
}
public func textureNamed(textureName: String!) -> SKTexture! {
return textureCache(textureName)
}
在“init”函数中:
- 函数声明中的预期标识符 -> (public func init -> 自我)
- 无法将“NSMutableDictionary”类型的值分配给“NSMutableDictionary”类型的值? -> (return textureCache = NSMutableDictionary())
对于“textureNamed”函数:
- 无法使用“(String!)”类型的参数列表调用“textureCache” -> (return textureCache(textureName))
如果有人可以帮助我,那就太棒了。
【问题讨论】:
标签: ios objective-c swift sprite-kit