0

I work with both Objective C / Swift class in my project and I have this problem :

I try to init an NSMutableArray which contains objects of type XXXIndicator in Swift according to my objective C method which is :

- (void)myMethod : (NSMutableArray<XXXIndicator*> *) indicatorsArray;

I create my Swift mutable array like that :

var indicatorsArrayCABarDatasource = [XXXIndicator]()

It works fine for now.

And when I call my objective-c method (which has been generated to a swift method by my bridging class), I get the following error :

"Cannot convert value of type [XXXIndicator] to expected argument type "NSMutableArray!"

How I call my method :

myView.myMethod(indicatorsArrayCABarDatasource)

Thanks for help.

1 Answer 1

1

The problem is that Swift arrays, even if they are declared with var, are bridged to NSArray instead of NSMutableArray, so you have to explicitly convert it to an NSMutableArray with its contructor, like:

NSMutableArray(array: indicatorsArrayCABarDatasource)
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you it works. Yes I just noticed that my generated method in swift was : public func createWithPercentBarWithArrayOfIndicators(indicatorsArray: NSMutableArray!)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.