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
arrays can't contain nil. There is a special object, NSNull ( [NSNull null] ), that serves as a placeholder for nil.
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 .
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>
Swift Array contains() The contains() method checks whether the specified element is present in the array or not.
Declare sounds as
var sounds: [Sound] = []
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] = []
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With