I get the error:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSA
Here is my code:
static NSArray * clone(NSArray * a, NSUInteger b)
{
// return a.slice(b);
return [a subarrayWithRange:NSMakeRange(b, a.count - b)];
}
// swap: function(a, b) {
static NSArray * swap(NSArray *a, NSUInteger b)
{
NSMutableArray * array = [NSMutableArray arrayWithArray:a];
// var t1, t2;
id t1, t2;
// t1 = a[0];
t1 = array.firstObject;
// t2 = a[b % a.length];
t2 = array[b % a.count];
// a[0] = t2;
array[1] = t2;
// a[b] = t1;
array[b] = t1;
// return a;
return array.copy;
}
I'm confused on why it is giving me the error. This is just a snippet of the code, This comes from a modified version of HCYoutubeParser.
arrayis empty which means that theaarray is empty. Find where you callswapand see why you pass in an empty array. Better yet, fix yourswapfunction so it handles arrays with any number of elements.