[swift-evolution] Suppress unused result warnings on try? if attempted statement does not return

Charlie Monroe charlie at charliemonroe.net
Fri Jun 17 06:31:06 CDT 2016


> On Jun 17, 2016, at 1:20 PM, Brent Royal-Gordon <brent at architechies.com> wrote:
> 
>> The required _ = try? on what used to be a BOOL result in ObjC is incredibly annoying, mostly with NSXML* classes on OS X where you really don't care about the error 99% of the time, but care just about the result (nodesForXPath, etc).
> 
> Are you in control of the XPath strings? If so, you should probably be using `try!`, because any mistake in your queries would be a programmer error.

I might be, but I've come across XMLs where the XPaths were correct (confirmed), yet the nodes(forXPath:) failed with an error. Mostly when multiple namespaces were present.

> I'm also not sure why you would call `nodes(forXPath:)` in void context at all—it doesn't have any useful side effects.

Sorry, this is my fault, kind of got side-tracked since I've recently dealt quite a lot with XML and it was freshly in my mind.

> 
> -- 
> Brent Royal-Gordon
> Architechies
> 



More information about the swift-evolution mailing list