• 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: NSTextField binding returns nil not empty string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTextField binding returns nil not empty string


  • Subject: Re: NSTextField binding returns nil not empty string
  • From: Keary Suska <email@hidden>
  • Date: Tue, 30 Apr 2013 13:51:40 -0600

On Apr 30, 2013, at 1:14 PM, Chris Paveglio wrote:

> What is the best way to handle this? I have a table view (using cell views) which has multiple text fields in it. I have an arrayController that holds an array of the custom objects that hold the data for each tableCellView (row). The array is made in the appDelegate and it always consists of text or empty text strings. It all works great as described.
>
> When I edit the text in the fields, if I remove all the text from one field, it must be returning nil back to the bound object. This messes things up later, because I need to return an empty string for each of the ivars in my custom object, not nil.
>
> So, my way to get around this was to essentially check if the object's ivar was nil, and if so then return empty string when called upon. This works just fine and I think it's efficient enough.
>
> But is there an even better way to handle that? I tried using "null placeholder" in the IB/binding options but that didn't seem to work. The ivars for the custom object aren't set to "strong" and I tried that but that didn't seem to help either. Is there anything I'm missing or does an NSTextField always return "nil" when a value is removed from it, or can I force it to return an empty string?

Yes, NSTextField has (IMHO) an imperfect understanding of the difference between nil and empty string. I feel your pain.

A slightly better approach might be to use key-value validation, as such:

-(BOOL)validateHeadline:(id *)ioValue error:(NSError **)outError
{
	if ( *ioValue == nil )
		*ioValue = @"";
	return YES;
}

This way you don't add side-effects to your accessors, and avoid hard to debug issues if you happen to use the ivar directly somewhere down the road.

HTH,

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"


_______________________________________________

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: 
 >NSTextField binding returns nil not empty string (From: Chris Paveglio <email@hidden>)

  • Prev by Date: Strange tracking rect problem
  • Next by Date: Unwind segues
  • Previous by thread: NSTextField binding returns nil not empty string
  • Next by thread: Strange tracking rect problem
  • Index(es):
    • Date
    • Thread