[swift-corelibs-dev] NSAttributedString attributesAtIndex return an optional.
James Lee
james at jelee.co.uk
Tue Dec 8 09:31:40 CST 2015
>
> Personally, if I indexed past the end of an attributed string, I would expect a precondition to fail and (since Swift can't catch assertion failures) my app to crash. (And from what I can tell, the Apple Foundation versions of these APIs do not return an optional.)
>
> --
> Brent Royal-Gordon
> Architechies
>
It is worth noting that the current OSX documentation does raise an NSRangeException in the case discussed above. With the throw capabilities in Swift 2 this makes sense.
As you have said, it seems a lot of Foundation API's do not return Optionals. I feel this a hangover from ObjC where an empty object (in this case an NSDictionary) would be returned. To me this is what Optionals are there to replace.
More information about the swift-corelibs-dev
mailing list