Has the syntax for NSArray arrayWithObject changed in recent Sketch versions?

125 views Asked by At

I developed a plugin that includes an array of acceptable file extensions. Up until recent versions of Sketch, the syntax looked like:

var fileTypes = [NSArray arrayWithObjects:@'scss',@'less',@'css',nil];

An error is being thrown, stating: ObjC method arrayWithObjects: requires 1 argument, but JavaScript passed 4 arguments

I researched the NSArray arrayWithObjects syntax and attempted to update my code based on the documentation:

NSString *strings[3];
strings[0] = @'scss';
strings[1] = @'less';
strings[2] = @'css';
NSArray *fileTypes = [NSArray arrayWithObjects:strings count:3];

No matter how I attempt to update the syntax, it throws a different error:

SyntaxError: Left hand side of operator '=' must be a reference..

Not being familiar with ObjC programming, can anyone help with the correct syntax for saving a reference fileTypes that equals three string values?

1

There are 1 answers

0
UXDart On BEST ANSWER

I assume you mean in a Sketch plugin or script... just use this:

var fileTypes = NSArray.arrayWithArray(['scss', 'less', 'css']);