将customobject作为参数从目标C传递到c ++

时间:2018-07-04 05:27:55

标签: c++ ios objective-c

在我的应用中,我正在从c++调用objective-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");
        }
    });
}

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

1 个答案:

答案 0 :(得分:1)

要实现此目标,您必须将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];