• 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: Strange Analyser Warning/Error
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Strange Analyser Warning/Error


  • Subject: Re: Strange Analyser Warning/Error
  • From: Michael Babin <email@hidden>
  • Date: Mon, 08 Feb 2016 07:55:48 -0600

> On Feb 8, 2016, at 7:15 AM, Dave <email@hidden> wrote:
>
> Look at this code:
>
> myUserInfo = [self.pUserIDDict objectForKey: theUserInfo.pUserID];
> if (myUserInfo != nil)
> 	{
> 	LTWAssertAlways(@"myUserInfo - Dupe ID!!!!!!!!!!");
> 	}
>
> if (theUserInfo.pUserID != nil)												//Remove this Line for Warning
> 	[self.pUserIDDict setObject: theUserInfo forKey: theUserInfo.pUserID];		//Warning on this line!
> }
>
>
> I get a warning saying that Key argument for setObjectForKey cannot be nil? I am wondering why it suddenly started moaning about this here and not other places were it is used and could be nil, like this:
>
> myUserInfo = [self.pUserIDDict objectForKey: theUserInfo.pUserID];
>
> This is the only place I’ve seen this warning and I’m using keys that could be nil in lots of places (without any problems as I obviously make sure that I don’t pass a nil…..

In the case where you do not see a warning, you are calling -[NSDictionary objectForKey:] which accepts a nil key value (returning nil).

In the case where you do see a warning, you are calling -[NSMutableDictionary setObject:forKey:] which does not accept a nil key value (nor a nil object value) and will throw an exception if you attempt to do so at runtime.


_______________________________________________

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


  • Follow-Ups:
    • Re: Strange Analyser Warning/Error
      • From: Dave <email@hidden>
References: 
 >Strange Analyser Warning/Error (From: Dave <email@hidden>)

  • Prev by Date: Strange Analyser Warning/Error
  • Next by Date: Re: Strange Analyser Warning/Error
  • Previous by thread: Strange Analyser Warning/Error
  • Next by thread: Re: Strange Analyser Warning/Error
  • Index(es):
    • Date
    • Thread