将自定义对象作为参数从目标 C 传递到 C++

pass customobject as argument from objective C to c++

本文关键字:C++ 目标 对象 自定义 参数      更新时间:2023-10-16

在我的应用程序中,我正在从objective-c调用一个c++函数,该函数将参数作为键值pair<String:String>

我能够成功地通过一对std::map<std::string, std::string> args,但现在我想通过字典。

我试图谷歌它,但我无法理解它。

为了更好地理解,这是我的代码:

+(void)createChatRoom:(NSDictionary *)chatRoomInfo forCompanyJSON:(NSDictionary *)companyJsonString completion:(void(^)(BOOL))completionHandler
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
@autoreleasepool{
NSString *strOwner = [chatRoomInfo objectForKey:@"owner"];
NSString *strCreator = [chatRoomInfo objectForKey:@"creator"];
NSString *strSubject = [chatRoomInfo objectForKey:@"subject"];
NSString *strProfilePic = [chatRoomInfo objectForKey:@"profilePic"];
NSInteger isPublic = [[chatRoomInfo objectForKey:@"isPublic"]boolValue] ? 1 :0;
NSString *strDescription = [chatRoomInfo objectForKey:@"description"];
NSString *strStatus = [chatRoomInfo objectForKey:@"status"];
std::map<std::string, std::string> args;
args["owner"] = std::string([strOwner UTF8String]);
args["creator"] = std::string([strCreator UTF8String]);
args["subject"] = std::string([strSubject UTF8String]);
args["profilePic"] = std::string([strProfilePic UTF8String]);
args["isPublic"] = isPublic;
args["description"] = std::string([strDescription UTF8String]);
args["status"] = std::string([strStatus UTF8String]);
args["company"] = **//Here i want to pass dictonary**
//Code to set the Log file path for iOS app, to avoid the crash on Logger
//Code to call the web service
WS::Response resp = WS::createRoom(args);
//Print the web service response in console window
NSString *response_body = [NSString stringWithCString:resp.body.c_str() encoding:[NSString defaultCStringEncoding]];
NSLog(@"%@", response_body);
NSLog(@"Response fetched successfully");
}
});
}

任何帮助或建议都会对我有所帮助。

要实现它,您必须将args声明为std::map<std::string, id>

std::map<std::string, id> args;
args["owner"] = strOwner;
args["creator"] = strCreator;
args["subject"] = strSubject;
args["profilePic"] = strProfilePic;
args["isPublic"] = @(isPublic);
args["description"] = strDescription;
args["status"] = strStatus;
args["company"] = [NSDictionary new];