3
여기서 사용자 정의 글꼴을 초기화하려하지만 오류를 표시하려고합니다.swift 4 : '[UIFontDesciptor.AttributeName : Any]'유형의 색인에 'String'유형의 색인을 붙일 수 없습니다.
extension UIFont {
@objc convenience init(myCoder aDecoder: NSCoder) {
if let fontDescriptor = aDecoder.decodeObject(forKey: "UIFontDescriptor") as? UIFontDescriptor {
if let fontAttribute = fontDescriptor.fontAttributes["NSCTFontUIUsageAttribute"] as? String { // HERE SHOWING THE ERROR
var fontName = ""
switch fontAttribute {
case "CTFontRegularUsage":
fontName = appFontName
case "CTFontEmphasizedUsage", "CTFontBoldUsage":
fontName = appFontBoldName
case "CTFontObliqueUsage":
fontName = appFontItalicName
default:
fontName = appFontName
}
self.init(name: fontName, size: fontDescriptor.pointSize)!
}
else {
self.init(myCoder: aDecoder)
}
}
else {
self.init(myCoder: aDecoder)
}
}
...
}
이것은 swift-3.2에서 완벽하게 작동합니다. 그러나 신속한 4.0으로 실행되지 않습니다. 도와주세요. 미리 감사드립니다.
감사 @vadian 확장자가없는 수는 확장을
을 선언 할 수 있습니다, 그것은 나를 위해 작동합니다! –