Swift Mutable Array in C

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

A property is declared like this:

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

C sees this as NSArray(not mutable), so I cannot change its elements. Declaring a property as NSMutableArraydoes not help either.

What would be the right approach?

Thanks.

+4
source share
2 answers

If you need to pass your array only to the C function, then the easiest way is to pass the pointer argument using the operator and so:

your_c_func(arg1, arg2, &Triggers);

If you need to do something more advanced, you will have to play with UnsafeBufferPointers and friends.

Here are some links to get you started with this:

Apple Swift Blog

Swift Russ Bishop

+1

, Objective-C Interop. NSMutableArray, - , .

0

Source: https://habr.com/ru/post/1627047/


All Articles