例えば、String <-> NSAttribut
1 @objc(S2ASTransformer) class 2 S2ASTransf ormer : NSValueTra nsformer { 3 4 override static func 5 transforme dValueClas s() -> AnyClass { 6 return NSAttribut edString.self 7 } 8 override static func 9 allowsReve rseTransfo rmation() -> Bool { 10 return true 11 } 12 override func 13 transforme dValue( p: AnyObject? ) -> AnyObject { 14 if let w = p as? String { return NSAttribut edString( string: w ) } else { return NSAttribut edString() } 15 } 16 override func 17 reverseTra nsformedVa lue( p: AnyObject? ) -> AnyObject { 18 if let w = p as? NSAttribut edString { return w.string } else { return "" } 19 } 20 21 } 22
こんなの作ってこうやって登録
1 func 2 applicationDidFinish Launching( p: NSNotifica tion ) { 3 NSValueTra nsformer.setValueTr ansformer( S2ASTransf ormer(), forName: "S2ASTransf ormer" ) 4 } 5 6
posted by
Saturn
on Sat 26 Mar 2016
at 15:56