Re: Aggravation trying to implement NSValueTransformer subclasses in Swift
Re: Aggravation trying to implement NSValueTransformer subclasses in Swift
- Subject: Re: Aggravation trying to implement NSValueTransformer subclasses in Swift
- From: Quincey Morris <email@hidden>
- Date: Thu, 14 May 2015 17:56:52 +0000
On May 14, 2015, at 08:40 , William Squires <email@hidden> wrote:
>
> I'd like to know how to properly write a value transformer in Swift.
Something like this, I expect:
> class StringNotNilTransformer: NSObject {
>
> static var transformedValueClass: AnyClass { return NSNumber.self }
> static let allowsReverseTransformation = false
>
> func transformedValue (value: AnyObject?) -> AnyObject? {
> if let string = value as? String {
> return NSNumber (bool: string != "");
> }
> return NSNumber (bool: false);
> }
> }
I only checked this in a playground, but I suspect the following slightly simpler version would also work too:
> class StringNotNilTransformer: NSObject {
>
> static var transformedValueClass: AnyClass { return NSNumber.self }
> static let allowsReverseTransformation = false
>
> func transformedValue (value: AnyObject?) -> AnyObject? {
> if let string = value as? String {
> return string != "";
> }
> return false;
> }
> }
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden