我正在将 cocoapod 用于 ibanimatable。我之前将它与 xcode 一起使用并且工作正常。但是现在当我更新 pod 时它开始给我错误。
public extension PlaceholderDesignable where Self: UITextField {
var placeholderText: String? { get { return "" } set {} }
public func configurePlaceholderColor() {
let text = placeholder ?? placeholderText
if let placeholderColor = placeholderColor, let placeholder = text {
attributedPlaceholder = NSAttributedString(string: placeholder, attributes: [.foregroundColor: placeholderColor])
}
}
}
下面一行给我的错误是
attributedPlaceholder = NSAttributedString(string: placeholder, attributes: [.foregroundColor: placeholderColor])
类型“String”没有成员“foregroundColor”
请告诉我如何解决这个问题?
最佳答案
根据 here ,属性键不是在 String
中声明的,而是在 NSAttributedStringKey
中声明的。这意味着您不能使用方便的“只需在此处放一个点,编译器就会知道您的意思”语法糖。键是字符串,因此编译器认为您指的是 String.foregroundColor
,但显然这样的东西不存在。
要解决此问题,请正确编写类型名称:
NSAttributedString(string: placeholder, attributes: [NSAttributedStringKey.foregroundColor: placeholderColor])
关于ios - xcode 9 中的 IBanimitable 问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46904048/