Xcode 7 (7A176x): [Swift] Array and ContiguousArray documentation with regards to memory layout in the case of bridging should be more explicit

Originator:janoschhildebrand
Number:rdar://22205682 Date Originated:09-Aug-2015
Status:Open Resolved:
Product:Documentation Product Version:Xcode 7 (7A176x)
Classification:Enhancement Reproducible:N/A
 
Summary:
I would like the documentation for Array and ContiguousArray to be clarified with regards to memory layout and bridging. The documentation has a lot of information on this subject but parts of it are somewhat vague and should be stated more explicitly.

Mainly I would like clarification for the following points:

Objective-C Bridge
* Whether Arrays created in Swift always use contiguous storage, i.e. only Arrays bridged from ObjC (where Element is a class or @objc protocol type) might use non-contiguous storage.
Currently, the documentation seems to leave open the possibility that Arrays created in Swift can have non-contiguous storage but does not outright say so. I would prefer for this to be made explicit either way.

Bridging From Objective-C
* Whether Arrays where Element is bridgeable but not a class or @objc protocol type will always have contiguous storage when bridged from ObjC? (For example, [AnyObject] bridged to [Int]).
My understanding of the documentation is that this is true, however I think this should be made more explicit as the documentation is a bit vague about this case.

Bridging To Objective-C
* Likewise, bridging an Array where Element is not a class or @objc protocol type to ObjC does not change the underlying storage for the Swift Array, i.e. is is still contiguous? (For example, [Int] to [AnyObject])
Again this is my understanding from the documentation but I think this should be stated explicitly as well.

ensureCapacity() & Objective-C Bridge
* The documentation for ensureCapacity() indicates that it ensures the Array has contiguous storage. Does this mean that the Array will have contiguous storage after the call, even if the array was a non-contigous bridged array and does not need to be resized to have the given capacity? If so, I would like for this to be stated more explicitly. Either in the section on bridging or in the documentation for ensureCapacity(), referencing the bridging case.


Version:
Array Structure Reference:
https://developer.apple.com/library/prerelease/ios/documentation/Swift/Reference/Swift_Array_Structure/index.html#//apple_ref/doc/uid/TP40015178

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!