# \#array

**URL:** https://forums.swift.org/tag/array/63.md

[Latest](https://forums.swift.org/latest.md) · [Categories](https://forums.swift.org/categories.md) · [Tags](https://forums.swift.org/tags.md)

---

## [The ArrayT Transformer, or tuple-ized initializers and closure parameters that initializes several Arrays at once?](https://forums.swift.org/t/the-arrayt-transformer-or-tuple-ized-initializers-and-closure-parameters-that-initializes-several-arrays-at-once/90926)

<div class="topic-metadata">

**Author:** [@Jerry1144](https://forums.swift.org/u/Jerry1144)\
**Replies:** 3\
**Last updated:** [November 20, 2026, 4:19pm UTC](https://forums.swift.org/t/the-arrayt-transformer-or-tuple-ized-initializers-and-closure-parameters-that-initializes-several-arrays-at-once/90926 "2026-11-20T16:19:00Z")

</div>

Sometimes I wish I could do this: let a : \[T1\], b : \[T2\] // func make\_data(idx) -\> (T1, T2) // UnsafeMutableBufferPointer version (a,b) = .init(unsafeUninitializedCapacity: 8) { (ptr1, ptr2), (cnt1, cnt2) in for i in…

---

## [Copy-on-write behaviour of collection types](https://forums.swift.org/t/copy-on-write-behaviour-of-collection-types/88184)

<div class="topic-metadata">

**Author:** [@EndBird](https://forums.swift.org/u/EndBird)\
**Replies:** 2\
**Last updated:** [July 10, 2026, 12:53am UTC](https://forums.swift.org/t/copy-on-write-behaviour-of-collection-types/88184 "2026-07-10T00:53:17Z")

</div>

In docs, it says “Collections defined by the Swift standard library like arrays, dictionaries, and strings use an optimization to reduce the performance cost of copying. Instead of making a copy immediately, these collec…

---

## [Are collection types shallow-copiers?](https://forums.swift.org/t/are-collection-types-shallow-copiers/88185)

<div class="topic-metadata">

**Author:** [@EndBird](https://forums.swift.org/u/EndBird)\
**Replies:** 2\
**Last updated:** [July 10, 2026, 12:52am UTC](https://forums.swift.org/t/are-collection-types-shallow-copiers/88185 "2026-07-10T00:52:05Z")

</div>

For collections — which are value types —that contain reference-typed instances, when they are copied, do the elements get copied over as well? My guess is no, since that feels confusing given that the elements are refer…

---

## [Clarify 'long term storage' of ArraySlice?](https://forums.swift.org/t/clarify-long-term-storage-of-arrayslice/82180)

<div class="topic-metadata">

**Author:** [@thecoolwinter](https://forums.swift.org/u/thecoolwinter)\
**Replies:** 6\
**Last updated:** [September 17, 2025, 10:54pm UTC](https://forums.swift.org/t/clarify-long-term-storage-of-arrayslice/82180 "2025-09-17T22:54:31Z")

</div>

Hello! I’m developing a data structure where I’m creating a structured representation of an unordered, idempotent representation. I’d ideally like to avoid copying data from structure A to structure B, and my thought was…

---

## [InlineArray conformance to common protocols](https://forums.swift.org/t/inlinearray-conformance-to-common-protocols/81585)

<div class="topic-metadata">

**Author:** [@tera](https://forums.swift.org/u/tera)\
**Replies:** 2\
**Last updated:** [August 12, 2025, 12:53pm UTC](https://forums.swift.org/t/inlinearray-conformance-to-common-protocols/81585 "2025-08-12T12:53:18Z")

</div>

Are there plans to make InlineArray conforming to standard protocols? '\[3 of Int\]' does not conform to protocol 'Equatable' '\[3 of Int\]' does not conform to 'Encodable' '\[3 of Int\]' does not conform to 'Decodable'

---

## [Creating an array of random numbers in Swift is slow](https://forums.swift.org/t/creating-an-array-of-random-numbers-in-swift-is-slow/80022)

<div class="topic-metadata">

**Author:** [@wigging](https://forums.swift.org/u/wigging)\
**Replies:** 54\
**Last updated:** [June 13, 2025, 1:27pm UTC](https://forums.swift.org/t/creating-an-array-of-random-numbers-in-swift-is-slow/80022 "2025-06-13T13:27:05Z")

</div>

I'm trying to create a Swift function that creates an array of random numbers similar to the numpy.random.rand function in the NumPy package. This example creates a large NumPy array with random numbers. I am using uv t…

---

## [Sorry for being a relative noob - how to create a class and an empty array](https://forums.swift.org/t/sorry-for-being-a-relative-noob-how-to-create-a-class-and-an-empty-array/78279)

<div class="topic-metadata">

**Author:** [@wayned321](https://forums.swift.org/u/wayned321)\
**Replies:** 2\
**Last updated:** [March 4, 2025, 9:32pm UTC](https://forums.swift.org/t/sorry-for-being-a-relative-noob-how-to-create-a-class-and-an-empty-array/78279 "2025-03-04T21:32:15Z")

</div>

I'm working on a function that generates "random numbers" that works okay, but the implementation leaves things that need to migrated to a class. The class may work, but I'm trying to create three empty arrays of type In…

---

## [Arrays and Initialisation: Bug or "feature"? (and some interesting array trickery!)](https://forums.swift.org/t/arrays-and-initialisation-bug-or-feature-and-some-interesting-array-trickery/77644)

<div class="topic-metadata">

**Author:** [@geotech](https://forums.swift.org/u/geotech)\
**Replies:** 6\
**Last updated:** [February 4, 2025, 12:09pm UTC](https://forums.swift.org/t/arrays-and-initialisation-bug-or-feature-and-some-interesting-array-trickery/77644 "2025-02-04T12:09:21Z")

</div>

So is this a bug or feature or I am not understanding the rules! I create a variable: @State public var thisSite: bores The error I get when I create a variable is: Return from initializer without initializing all stor…

---

## [Convert arrays of Int32 to arrays of Int for integer arithmetic](https://forums.swift.org/t/convert-arrays-of-int32-to-arrays-of-int-for-integer-arithmetic/76356)

<div class="topic-metadata">

**Author:** [@wigging](https://forums.swift.org/u/wigging)\
**Replies:** 15\
**Last updated:** [December 6, 2024, 7:13pm UTC](https://forums.swift.org/t/convert-arrays-of-int32-to-arrays-of-int-for-integer-arithmetic/76356 "2024-12-06T19:13:56Z")

</div>

The function shown below performs element-wise addition of two vectors. The vectors are arrays containing integer values of type Int. The printed output of the result is \[5, 7, 9, 11, 13\]. I am only showing addition here…

---

## [Vector, a fixed-size array](https://forums.swift.org/t/vector-a-fixed-size-array/75264)

<div class="topic-metadata">

**Author:** [@Alejandro](https://forums.swift.org/u/Alejandro)\
**Replies:** 270\
**Last updated:** [November 19, 2024, 5:36pm UTC](https://forums.swift.org/t/vector-a-fixed-size-array/75264 "2024-11-19T17:36:04Z")

</div>

Hi Evolution, with the recent pitch for Integer Generics, we finally have a way to express counts, capacities, and more for types. The most natural extension from that pitch in my opinion is finally letting Swift have fi…

---

## [Calculate shape of N-dimensional array from a flat array](https://forums.swift.org/t/calculate-shape-of-n-dimensional-array-from-a-flat-array/74553)

<div class="topic-metadata">

**Author:** [@wigging](https://forums.swift.org/u/wigging)\
**Replies:** 11\
**Last updated:** [September 14, 2024, 6:56pm UTC](https://forums.swift.org/t/calculate-shape-of-n-dimensional-array-from-a-flat-array/74553 "2024-09-14T18:56:57Z")

</div>

I have a flat array as shown below that represents a 3D array. The example prints the shape of the array as (2, 3, 4) which means there are two arrays each with a size of 3-by-4 elements. let arr = \[\[\[1, 2, 3, 4\], …

---

## [Print an N-dimensional array](https://forums.swift.org/t/print-an-n-dimensional-array/74082)

<div class="topic-metadata">

**Author:** [@wigging](https://forums.swift.org/u/wigging)\
**Replies:** 26\
**Last updated:** [August 25, 2024, 4:22am UTC](https://forums.swift.org/t/print-an-n-dimensional-array/74082 "2024-08-25T04:22:38Z")

</div>

I can print a 2D array by providing the shape of a flat array as shown below: let numbers: \[Float\] = \[1, 2, 3, 4, 5, 6\] let shape = \[2, 3\] var result = "" for i in 0..\<shape\[0\] { for j in 0..\<shape\[1\] { le…

---

## [Subscript for 4D and higher dimensions in a ShapedArray](https://forums.swift.org/t/subscript-for-4d-and-higher-dimensions-in-a-shapedarray/73735)

<div class="topic-metadata">

**Author:** [@wigging](https://forums.swift.org/u/wigging)\
**Replies:** 13\
**Last updated:** [August 7, 2024, 1:31am UTC](https://forums.swift.org/t/subscript-for-4d-and-higher-dimensions-in-a-shapedarray/73735 "2024-08-07T01:31:40Z")

</div>

Below is a ShapedArray structure for working with 1D, 2D, and 3D arrays. The DataBuffer class holds a reference to the underlying mutable buffer for data storage. A flatIndex function determines the one-dimensional index…

---

## [Array.removeAll(where:) duplication](https://forums.swift.org/t/array-removeall-where-duplication/70597)

<div class="topic-metadata">

**Author:** [@tera](https://forums.swift.org/u/tera)\
**Replies:** 5\
**Last updated:** [March 12, 2024, 4:38pm UTC](https://forums.swift.org/t/array-removeall-where-duplication/70597 "2024-03-12T16:38:43Z")

</div>

Why is this method duplicated?

---

## [Swift Optimization Tips: Using Container Type Efficiently](https://forums.swift.org/t/swift-optimization-tips-using-container-type-efficiently/69489)

<div class="topic-metadata">

**Author:** [@vanvoorden](https://forums.swift.org/u/vanvoorden)\
**Replies:** 1\
**Last updated:** [February 13, 2024, 7:35pm UTC](https://forums.swift.org/t/swift-optimization-tips-using-container-type-efficiently/69489 "2024-02-13T19:35:47Z")

</div>

Swift Optimization Tips: Using Container Type Efficiently Hi! I'm following along with the Swift Optimization Tips documentation and had a few questions specifically about Using Container Types Efficiently.\[1\] In the e…

---

## [Array constructor from Mirror Subject?](https://forums.swift.org/t/array-constructor-from-mirror-subject/69781)

<div class="topic-metadata">

**Author:** [@jtint24](https://forums.swift.org/u/jtint24)\
**Replies:** 2\
**Last updated:** [February 2, 2024, 1:32am UTC](https://forums.swift.org/t/array-constructor-from-mirror-subject/69781 "2024-02-02T01:32:07Z")

</div>

This would be a new initializer for Array, allowing it to be created from a Subject, targeted at providing greater ease-of-use to tuples. The problem with Tuples Homogenous tuples are already the standard way of represe…

---

## [What is "@\_eagerMove"?](https://forums.swift.org/t/what-is-eagermove/69078)

<div class="topic-metadata">

**Author:** [@Kobe24](https://forums.swift.org/u/Kobe24)\
**Replies:** 4\
**Last updated:** [December 23, 2023, 6:25am UTC](https://forums.swift.org/t/what-is-eagermove/69078 "2023-12-23T06:25:34Z")

</div>

Hello, I'm Kobe, studying iOS and Swift in South Korea. It's very cold here in Korea as it's winter. I'm curious about the weather in the regions where all of you in the forum are located. :) The thing I'm curious abo…

---

## [Short Array optimisation](https://forums.swift.org/t/short-array-optimisation/68082)

<div class="topic-metadata">

**Author:** [@tera](https://forums.swift.org/u/tera)\
**Replies:** 24\
**Last updated:** [November 18, 2023, 5:14am UTC](https://forums.swift.org/t/short-array-optimisation/68082 "2023-11-18T05:14:00Z")

</div>

We don't optimise short array storage (e.g. "arrays up to 15 bytes could be stored inline") like we do with strings. Ditto for the quite frequent case of empty arrays, which optimisation would work for all array types if…

---

## [Constant u16 data](https://forums.swift.org/t/constant-u16-data/67844)

<div class="topic-metadata">

**Author:** [@bbrk24](https://forums.swift.org/u/bbrk24)\
**Replies:** 8\
**Last updated:** [October 15, 2023, 10:56am UTC](https://forums.swift.org/t/constant-u16-data/67844 "2023-10-15T10:56:49Z")

</div>

I know that string literals are emitted into the binary, but array literals are constructed at runtime. So, in some cases, it's preferable to use string literals over array literals for constant data. What if the consta…

---

## [One Terabyte Array Idea](https://forums.swift.org/t/one-terabyte-array-idea/66638)

<div class="topic-metadata">

**Author:** [@tera](https://forums.swift.org/u/tera)\
**Replies:** 12\
**Last updated:** [August 20, 2023, 2:28pm UTC](https://forums.swift.org/t/one-terabyte-array-idea/66638 "2023-08-20T14:28:29Z")

</div>

This deserves being in a separate thread. Continuing the discussion from Should we rename Deque?:

---

## [Why Can I Only Append a Struct to an Array Once?](https://forums.swift.org/t/why-can-i-only-append-a-struct-to-an-array-once/65601)

<div class="topic-metadata">

**Author:** [@louiscarbo](https://forums.swift.org/u/louiscarbo)\
**Replies:** 2\
**Last updated:** [June 16, 2023, 2:21am UTC](https://forums.swift.org/t/why-can-i-only-append-a-struct-to-an-array-once/65601 "2023-06-16T02:21:15Z")

</div>

I'm new to SwiftUI, and to coding in general, and I'm currently trying to build an app using SwiftUI. I have a problem that I was not able to solve, even after a careful review of my code, and with the help of GPT-4. S…

---

## [Calling though the original implementation in an override](https://forums.swift.org/t/calling-though-the-original-implementation-in-an-override/65464)

<div class="topic-metadata">

**Author:** [@tera](https://forums.swift.org/u/tera)\
**Replies:** 9\
**Last updated:** [June 9, 2023, 8:09pm UTC](https://forums.swift.org/t/calling-though-the-original-implementation-in-an-override/65464 "2023-06-09T20:09:44Z")

</div>

In my app I'm overriding array's subscript to get an additional functionality when array contains my elements (which are adhering to my ValueElement protocol): protocol ValueElement { ... } extension Array where El…

---

## [Referencing memory via a variety of Arrays](https://forums.swift.org/t/referencing-memory-via-a-variety-of-arrays/64554)

<div class="topic-metadata">

**Author:** [@Gavin\_Eadie](https://forums.swift.org/u/Gavin_Eadie)\
**Replies:** 1\
**Last updated:** [April 23, 2023, 5:10am UTC](https://forums.swift.org/t/referencing-memory-via-a-variety-of-arrays/64554 "2023-04-23T05:10:27Z")

</div>

I suspect this is really easy but it is evading me. I have a file representing a disk image read into memory as type Data. I want to be able to address this image as an array of Sectors and, in turn, address Sectors as…

---

## [Understanding type comparison of collection types](https://forums.swift.org/t/understanding-type-comparison-of-collection-types/63909)

<div class="topic-metadata">

**Author:** [@jbrunhuber](https://forums.swift.org/u/jbrunhuber)\
**Replies:** 20\
**Last updated:** [April 6, 2023, 12:36pm UTC](https://forums.swift.org/t/understanding-type-comparison-of-collection-types/63909 "2023-04-06T12:36:50Z")

</div>

Hi folks :wave: I'm trying to understand how Swift handles type comparison and typecasting of collection types. I'm attempting to filter a nested array based on its type: let array: \[Any\] = \[\[5\], \["five"\], \[String\](), …

---

## [Make Array.init(repeating: ...) with autoclosure](https://forums.swift.org/t/make-array-init-repeating-with-autoclosure/63879)

<div class="topic-metadata">

**Author:** [@dankinsoid](https://forums.swift.org/u/dankinsoid)\
**Replies:** 4\
**Last updated:** [March 22, 2023, 2:16pm UTC](https://forums.swift.org/t/make-array-init-repeating-with-autoclosure/63879 "2023-03-22T14:16:44Z")

</div>

Array has a convenience init public init(repeating repeatedValue: Element, count: Int) It's useful when you need an array of equal elements, but it could be used for generating an array of different values, for example…

---

## [Is a range of Ints actually an array?](https://forums.swift.org/t/is-a-range-of-ints-actually-an-array/63447)

<div class="topic-metadata">

**Author:** [@mango](https://forums.swift.org/u/mango)\
**Replies:** 6\
**Last updated:** [March 2, 2023, 9:43am UTC](https://forums.swift.org/t/is-a-range-of-ints-actually-an-array/63447 "2023-03-02T09:43:31Z")

</div>

If I have a range of type Int, i.e., (2…100) is that range in fact an array of Ints?

---

## [How do I append each element in an array?](https://forums.swift.org/t/how-do-i-append-each-element-in-an-array/62950)

<div class="topic-metadata">

**Author:** [@geniusPenguin](https://forums.swift.org/u/geniusPenguin)\
**Replies:** 5\
**Last updated:** [February 14, 2023, 8:43pm UTC](https://forums.swift.org/t/how-do-i-append-each-element-in-an-array/62950 "2023-02-14T20:43:20Z")

</div>

Hi, I'm trying to create an array that holds every card in card deck. Instead of manually writing out 52 separate elements, I'm creating 4 identical arrays containing the 13 cards, appending them with their respective su…

---

## [Array index error in Swift while doing  shuffle in string](https://forums.swift.org/t/array-index-error-in-swift-while-doing-shuffle-in-string/61931)

<div class="topic-metadata">

**Author:** [@SwiftGuy](https://forums.swift.org/u/SwiftGuy)\
**Replies:** 1\
**Last updated:** [December 9, 2022, 3:03am UTC](https://forums.swift.org/t/array-index-error-in-swift-while-doing-shuffle-in-string/61931 "2022-12-09T03:03:57Z")

</div>

I need to do the shuffle string in swift. When given a string("codeleet") and array of indices(\[4,5,6,7,0,2,1,3\]). I need to shuffle the character of the string in the position of indices. But when I am writing the follo…

---

## [Type constraint resolver issue with subscript function in SEMA? or some standard library magic?](https://forums.swift.org/t/type-constraint-resolver-issue-with-subscript-function-in-sema-or-some-standard-library-magic/61832)

<div class="topic-metadata">

**Author:** [@carlos42421](https://forums.swift.org/u/carlos42421)\
**Replies:** 0\
**Last updated:** [December 5, 2022, 1:12pm UTC](https://forums.swift.org/t/type-constraint-resolver-issue-with-subscript-function-in-sema-or-some-standard-library-magic/61832 "2022-12-05T13:12:04Z")

</div>

This is again one of those "what section do I put it in?" questions. I have a modified Array in my standard library that subscripts (and conforms to Collection) with a different Index type called ArrayIndex that's a sim…

---

## [@\_semantics("array.check\_subscript") is elided in my code](https://forums.swift.org/t/semantics-array-check-subscript-is-elided-in-my-code/61619)

<div class="topic-metadata">

**Author:** [@carlos42421](https://forums.swift.org/u/carlos42421)\
**Replies:** 0\
**Last updated:** [November 25, 2022, 5:09pm UTC](https://forums.swift.org/t/semantics-array-check-subscript-is-elided-in-my-code/61619 "2022-11-25T17:09:12Z")

</div>

Hiya, Here with the strange questions again! In my sample code, I'm not seeing the behaviour I expect from my standard library code when subscripting Array. My version of \_checkSubscript passes the subscript as an inou…

[Next page](https://forums.swift.org/tag/array/63.md?match_all_tags=true&page=1&tags%5B%5D=array)
