передать customobject в качестве аргумента из цели C в c ++ - PullRequest
0 голосов
/ 04 июля 2018

В моем приложении я вызываю 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 голосов
/ 04 июля 2018

Чтобы достичь этого, вы должны объявить 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];
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...