• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Aggravation trying to implement NSValueTransformer subclasses in Swift
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Aggravation trying to implement NSValueTransformer subclasses in Swift (From: William Squires <email@hidden>)
 >Re: Aggravation trying to implement NSValueTransformer subclasses in Swift (From: Quincey Morris <email@hidden>)
 >Re: Aggravation trying to implement NSValueTransformer subclasses in Swift (From: William Squires <email@hidden>)

  • Prev by Date: Re: Optionals? A better option!
  • Next by Date: Re: Optionals? A better option!
  • Previous by thread: Re: Aggravation trying to implement NSValueTransformer subclasses in Swift
  • Next by thread: Fast enumeration question.
  • Index(es):
    • Date
    • Thread