Check your Debugger Console, as it may be telling what you're doing wrong.
[file.list objectAtIndex:index]
If you're getting an NSRangeException, it may be because index
contains an index that is outside the bounds of the array. Remember that arrays in Cocoa are serial, not associative; if you remove an object, the indexes of all the objects that came after it will go down by 1, upholding the invariant that 0 ≤ (every valid index) < (count of objects in the array).
It could also be because you never declared a variable named index
.
NSString *fileName = [[file.list objectAtIndex:index] objectForKey:@"soundName"];
NSString *filePaht = [[NSBundle mainBundle] pathForResource:fileName ofType:@"aiff"];
If nothing is happening or you get an NSInternalInconsistencyException, it could be one of:
fileList
is nil
.
- The dictionary returned from
[file.list objectAtIndex:index]
does not have an object for the key soundName
.
If you got a “does not respond to selector” message in the Console, it may be one of:
file.list
is an object, but not an NSArray.
[file.list objectAtIndex:index]
is not an NSDictionary.
fileName
([[file.list objectAtIndex:index] objectForKey:@"soundName"]
) is not an NSString.
Remember that the class name you use when you declare the variable doesn't matter except to the compiler; at run time, it's just a variable holding a pointer to an object. The object can be of any class. It is perfectly valid to put something that isn't an NSString into an NSString *
variable; it simply carries a very high (near certain) risk of wrong behavior and/or crashing shortly thereafter.
Such a crash will usually manifest in the form of a “does not respond to selector” exception (after something sends the object a message that NSString objects, for example, should respond to, but that the object doesn't respond to because it isn't an NSString).
Whichever problem you're having, you can use the Debugger to investigate.