[swift-corelibs-dev] Bounds Checking on NSArray

Tony Parker anthony.parker at apple.com
Thu Dec 3 22:14:27 CST 2015


Hi there Daniel,


> On Dec 3, 2015, at 7:14 PM, Daniel Strokis <dstrokis at icloud.com> wrote:
> 
> Hi all, 
> 
> In swift-corelibs-foundation/Foundation/NSArray.swift on line 347 there is a comment that says TODO: Bounds checking . Since that just call objectAtIndex, I think the bounds checking should be done inside of objectAtIndex.

Note we have another pull request open in this area too: https://github.com/apple/swift-corelibs-foundation/pull/15

I asked there to rebase into a single commit; once that’s done, maybe we can accept that and then move it to the implementation of objectAtIndex.

> My question, though, is what should be returned if the index is out of the array bounds? The methods don’t throw, so I don’t think we can raise an exception. And I don’t think we can return nil because the method is supposed to return a non-optional AnyObject. What about using assert or precondition?
> 

We’ve made a decision to use fatalError(“description that makes sense”) in cases of programmer error. Obj-C Foundation would have thrown an exception (since we use ObjC exceptions exclusively for indication of programmer error there). 

> I’m super excited to be a part of this community!
> 

Glad to have you here.

- Tony

> Thanks,
> Daniel Strokis
> 
> _______________________________________________
> swift-corelibs-dev mailing list
> swift-corelibs-dev at swift.org
> https://lists.swift.org/mailman/listinfo/swift-corelibs-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-corelibs-dev/attachments/20151203/6edad8ff/attachment.html>


More information about the swift-corelibs-dev mailing list