4

I am trying to access a property of a Swift class using pure C code, since I'm in the Audio Thread.

The property is declared so:

var Triggers: [[Int]] = [[Int]]()

C sees this as a NSArray (non mutable) hence I can't modify its elements. Declaring the property as a NSMutableArray is also not helping.

What would be the correct approach?

Thanks.

2 Answers 2

1

If you only have to pass your array to C function then the easiest way is to pass pointer argument using the & operator like so

your_c_func(arg1, arg2, &Triggers);

If you have to do something more advanced then you will have to play with UnsafeBufferPointers and it's friends.

Here's some links to get you started on this:

Apple's Swift blog

Unsafe Swift by Russ Bishop

Sign up to request clarification or add additional context in comments.

Comments

0

I will say, that I have little experience with Objective-C Interop. But personally I would assign the contents of the immutable array to an NSMutableArray, and then perform modifications on the copy - if needed of course.

1 Comment

I'd need to modify the object's property. I won't be able to put the NSMutableArray back in the object

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.