I'am, welcher Parameter über die Funktion vonWie Parameter von ANYOBJECT passieren ... funktionieren müssen ANYOBJECT
NSAttributedString(attributes: [String : AnyObject]?, format: String, arguments: AnyObject...)
Und ich möchte eine allgemeine Funktion anpassen diese Funktion oben zu rufen. Also muss ich Parameter senden
arguments: AnyObject...
Aber dieser Parameter werden [ANYOBJECT] in meiner Funktion anpassen. Wie man es repariert?
aktualisieren:
Wenn ich Code verwenden Gebrüll:
typealias Function = ([String : AnyObject]?, String, [AnyObject]) -> NSAttributedString
let myAttributedString = unsafeBitCast(NSAttributedString(attributes:format:_:) , Function.self)
Es Fehler geben wird:
Use of unresolved identifier 'NSAttributedString(attributes:format:_:)'
Update: (Temp Lösung)
I hol dir eine te mp Lösung, die hässlich ist, aber gerade genug für mich funktioniert.
// NOTE: here arguments may be String or NSAttributedString
private func getAttributedString(withFormat format: String, _ arguments: AnyObject..., withUnderLine: Bool = false) -> NSAttributedString {
var attributes = [NSFontAttributeName: #someFont,
NSForegroundColorAttributeName: #someColor]
if withUnderLine {
attributes[NSStrikethroughStyleAttributeName] = NSUnderlineStyle.StyleSingle.rawValue
}
switch arguments.count {
case 0:
return NSAttributedString(attributes: attributes, format: format)
case 1:
return NSAttributedString(attributes: attributes, format: format, arguments[0])
case 2:
return NSAttributedString(attributes: attributes, format: format, arguments[0], arguments[1])
case 3:
return NSAttributedString(attributes: attributes, format: format, arguments[0], arguments[1], arguments[2])
case 4:
return NSAttributedString(attributes: attributes, format: format, arguments[0], arguments[1], arguments[2], arguments[3])
default:
assert(arguments.count <= 4)
return NSAttributedString(attributes: attributes, format: format, arguments[0], arguments[1], arguments[2], arguments[3])
}
}
Mögliches Duplikat von [Übergeben eines Arrays an eine Funktion mit variabler Anzahl von Argumenten in Swift] (http: // stac koverflow.com/questions/24024376/passing-an-array-to-a-function-with-variable-number-of-args-in-swift) – Andreas
Ich weiß, wie es mit Int zu tun, aber weiß nicht wie um dies mit AnyObject zu tun – JerryZhou
Oh, ist der Status von https://bugs.swift.org/browse/SR-128 nicht auf dem neuesten Stand? Wie machst du es mit Int? – Andreas