I'm trying to convert the following Objective-C code to Swift. In my Objective-C code, there's a static variable and its accessed from a class method.
@implementation SomeClass
static NSMutableArray *_items;
+ (void)someMethod {
[_items removeAll];
}
@end
Since you can't access types declared like this private var items = [AnyObject]()
from class functions in Swift, I created a stored property for it like this.
class var items: [AnyObject] {
return [AnyObject]()
}
And I'm trying to call a method on it from a class function like so.
class func someFunction() {
items.removeAll(keepCapacity: false)
}
But I get this error Immutable value of type '[AnyObject]' only has mutating members named 'removeAll'.
Can anyone please tell me what's the cause of this error and how to correct it?
Thank you.
var items:Array<AnyObject> = [];
"