I just got into swift coding and I am trying to follow a tutorial. but it seems as if the coder I'm following may have an older version, or I am doing something wrong. I am trying to make a sound object to make a soundboard. but when i try to add the sound file to the array using append, it says that the method append
is not a member of the NSArray
. can someone tell me what is the right way to do solve this?!]1
Asked
Active
Viewed 1.7k times
9
-
2You should work with Swift native type Array – Leo Dabus May 27 '15 at 06:38
4 Answers
11
You should work with Swift native type Array
var array: [Any] = []
if you know it will have only one type you can do as follow:
var intArray: [Int] = []
var doubleArray: [Double] = []
var stringArray: [String] = []

Leo Dabus
- 229,809
- 59
- 489
- 571
3
Swift and Foundation arrays are different types of objects.
Swift Array
declares a method called append
, NSMutableArray
(NSArray
is immutable you can't modify it after you created) doesn't declare that kind of method.
The solution is cast your NSArray
into an Array
type (using the as
operator, since they are bridged), or use the method -addObject:
on a NSMutableArray
, but first you need to make a -mutableCopy
of the NSArray

Andrea
- 26,120
- 10
- 85
- 131
1
NSArray
is an immutable object.
You have to use NSMutableArray
Here is the documentation

Jens
- 67,715
- 15
- 98
- 113
-
2even `NSMutableArray` will return same error. Shouldn't it be a type of inbuilt datatype `array` – Vivek Molkar May 27 '15 at 06:35
-