How to get the total number of elements that an array can contain without allocate new storage in Swift

3 Answers

0 votes
var arr = [5, 0, 2, 8];

print(arr.capacity);





/*
run:

4

*/

 



answered Jun 14, 2023 by avibootz
0 votes
var arr:[Int]  = [5, 0, 2, 8];

print(arr.capacity);





/*
run:

4

*/

 



answered Jun 14, 2023 by avibootz
0 votes
var arr = [Int]()

print(arr.capacity);





/*
run:

0

*/

 



answered Jun 14, 2023 by avibootz
...