• 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: How to fix "misuse of 'nonnull'" warnings in Xcode 7.3?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to fix "misuse of 'nonnull'" warnings in Xcode 7.3?


  • Subject: Re: How to fix "misuse of 'nonnull'" warnings in Xcode 7.3?
  • From: Sean McBride <email@hidden>
  • Date: Fri, 26 Feb 2016 16:40:21 -0500
  • Organization: Rogue Research Inc.

On Thu, 25 Feb 2016 13:31:45 -0800, Jens Alfke said:

>As an experiment I tried turning on the new “misuse of ’nonnull'”
>warning in Xcode 7.3, and got a ton of warnings. They all make sense,
>but assuming I were going to correct my code, I don’t know the best way
>go about it. For example, here’s a real warning reported in my project:
>	[hostArray addObject: url.host];	// Warning!
>Here the problem is that NSURL.host returns a nullable NSString, but -
>[NSArray addObject:]’s parameter is not nullable.
>
>If I know that the URLs I’m dealing with all have hostnames in them, I
>could just add an “!” after `url.host`. Except I can’t because this is
>Obj-C, not Swift. What’s the equivalent? Do I have to add a cast?
>	[hostArray addObject: (NSString* _Nonnull)url.host];
>
>If I don’t want to trust that the URL has a host, I can use `if let` to
>test it. But again, what’s the Obj-C equivalent? It seems like I’d need
>	NSString* _Nonnull host = url.host;
>	if (host)
>		[hostArray addObject: host];

Actually, seems:

	NSString* host = url.host;
	[hostArray addObject: host];

is enough to "fix" the warning.  ie add a temporary variable.  You could throw in an assert too:

	NSString* host = url.host;
 assert(host);
	[hostArray addObject: host];

Cheers,

--
____________________________________________________________
Sean McBride, B. Eng                 email@hidden
Rogue Research                        www.rogue-research.com
Mac Software Developer              Montréal, Québec, Canada

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >How to fix "misuse of 'nonnull'" warnings in Xcode 7.3? (From: Jens Alfke <email@hidden>)

  • Prev by Date: Aggregate targets in Xcode - is there any documentation on this anywhere?
  • Next by Date: Re: How to fix "misuse of 'nonnull'" warnings in Xcode 7.3?
  • Previous by thread: Re: How to fix "misuse of 'nonnull'" warnings in Xcode 7.3?
  • Next by thread: Re: How to fix "misuse of 'nonnull'" warnings in Xcode 7.3?
  • Index(es):
    • Date
    • Thread