'Convert NSArray (Swift) to vector (C++)
I'm trying to pass an integer NSArray from Swift to C++ (vector), and I'm using Objective-C as a bridge between them, where the conversion will take place. I've made a simple example below, where an array in Swift is passed to Objective-C, and it's converted to a vector to be passed to C++, where it'll perform some calculations and return the result as a string.
Sample.swift
let myArray: Array<Int> = [10, 24, 13, 34]
HelloWorldWrapper().returnArrayAsString(myArray)
Sample.mm
@implementation HelloWorldWrapper
- (NSString *) returnArrayAsString:(NSArray *) myArray {
vector<int> myVector;
for (int j = 0; j< 4; ++j) {
int myInt = myArray[j]; // error: Cannot initialize a variable of type 'int' with an rvalue of type 'id'
myVector.push_back(myInt)
}
}
There are quite a few other things, I've tried that also lead to errors. Ultimately my goal is to convert Array[Int] to vector to be used in C++.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
