我正在使用一个小图书馆创建一个带有某人名字缩写的图片。我有一个实际有效的类和一个类func class func imageWith(name: String?, textColor: UIColor = .white) -> UIImage?
我之前从未使用class func
,我通常会使用static
我想知道它是否可能用class func imageWith(name: [String]?, textColor: UIColor = .white) -> UIImage?
任何帮助都将不胜感激。
答案 0 :(得分:0)
您获得的错误消息是由于在Swift 3中,Objective-C运行时隐式可用方法,而Objective-C不支持重载。有两种方法可以解决这个问题:
或:
答案 1 :(得分:0)
这是一个Objective-C转换问题。
Objective-C在调用方法时没有对类强制执行类型区分,因此您不能使用具有相同名称的方法。
Swift看到的地方
class func imageWith(name: String?, textColor: UIColor = .white) -> UIImage?
class func imageWith(name: [String]?, textColor: UIColor = .white) -> UIImage?
Objective-C看
+(id)imageWithName: (id) name andTextColor: (id) textColor
+(id)imageWithName: (id) name andTextColor: (id) textColor
<强>解决方案:强>
你需要做的就是改变你的命名,.e.g。
class func imageWith(names: [String]?, textColor: UIColor = .white) -> UIImage?
将导致Objective-C看到
+(id)imageWithNames: (id) names andTextColor: (id) textColor