I want to convert values of std::map to NSMutableArray element.
My CPP code is passing std::map (with one int and std::string) to an Objective-C function using interface function.
But i am not able to convert this std::map to NSMutableArray.
CPP Code:
------------------------------------------------------------------
typedef std::map<int, std::string> TemList;
temList temList;
temList[10]="an element";
temList[23]="another element";
temList[545]="last";
passing this map to an objective-c code using interface function.
Objective-c Code
------------------------------------------------------------------
- (void) testListUpdate:(const TemList&) pList
{
NSMutableArray *mArray = [NSMutableArray alloc]init];
for (TemList::const_iterator ii = pList.begin(); ii != pList.end(); ++ii)
{
ListItem item = [[ListItem alloc] init]
// PROBLEM **** I am Not able to convert this ******
item.name = ii->second.c_str();
item.mId = (int) ii->first;
[mArray addObject:item];
//printf("OBJC Value[%s]: Key[%d]\n", ii->second.c_str(), ii->first);
}
}
// Interface function implementation
void interfaceListUpdate(void *self, const TemList& pList)
{
printf("ObjectiveC Interface Function size[%d]\n", pList.size());
[(id) self testListUpdate:pList];
}
// Using this struct as Array item
@interface ListItem : NSObject
{
NSString *name;
int mId;
}
@end
Also i want to use mArray
for displaying table view rows.
How should i do it.
std::string::c_str()
returns a plain C character array of the string represented by the C++string
object (since the internal storage ofstd::string
is opaque)