Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"NSArray' does not have a member named 'append'

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

enter image description here

like image 574
i.zain595 Avatar asked May 27 '15 06:05

i.zain595


People also ask

Can NSArray contain nil?

arrays can't contain nil. There is a special object, NSNull ( [NSNull null] ), that serves as a placeholder for nil.

What is difference between array and NSArray in IOS?

Array is a struct, therefore it is a value type in Swift. NSArray is an immutable Objective C class, therefore it is a reference type in Swift and it is bridged to Array<AnyObject> . NSMutableArray is the mutable subclass of NSArray .

What is array and NSArray in Swift?

Array is a Swift construct, and generic struct, which means that it can be an array of any specific type (Int, String, etc.) [T] is syntactic sugar for Array<T> . NSArray is an Objective-C construct that can hold any Objective-C object and is transparently mapped to and from Array<AnyObject>

How do you check if an element exists in an array Swift?

Swift Array contains() The contains() method checks whether the specified element is present in the array or not.


2 Answers

Declare sounds as

var sounds: [Sound] = []
like image 191
CQH Avatar answered Sep 23 '22 02:09

CQH


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] = []
like image 44
Leo Dabus Avatar answered Sep 22 '22 02:09

Leo Dabus