On Dec 9, 2015, at 14:35 , Rick Mann <[email protected]> wrote:
>
> If I have var foo : [Int], how can I get that type, Int? I need to get the
> size of each element.
I imagine there’s a direct way, but I can’t find it in a program. You can do
something like this:
strideofValue (foo [0]) // but this requires foo.count
!= 0, or:
strideof (foo [0].dynamicType) // which seems to work in a
playground even for empty arrays
Note that I’m not sure there’s an API guarantee that the Array<> elements are
stored contiguously in memory. If you want that, you should probably use
ContiguousArray<> instead. (That also gives you API to directly/unsafely access
the memory too, IIRTGHF** correctly.)
Do be careful, though. If you’re accessing Ints raw-ly, and (say) saving them
or transmitting them to another application or platform, you might also have to
worry about element size and endianness differences, theoretically.
** "If I Read The Generated Header File"
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]