将自定义对象作为参数从目标 C 传递到 C++
pass customobject as argument from objective C to c++
在我的应用程序中,我正在从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];
相关文章:
- 如何(从固定列表中)选择一个数字序列,该序列将与目标数字相加
- C++A*算法并不总是在路径中具有目标节点
- 基于树莓pi的tensorflow lite量化ssd目标检测
- 为测试目标创建具有不同源文件夹的文件
- 使用源向量作为目标
- 是否可以用C++/WinRT将windows 10.0.14393作为目标
- 在 CMake 中为每个目标设置编译器/链接器标志
- qmake:检测目标位宽(32 位或 64 位)
- 如何在 CMake 中对目标依赖项进行分组?
- 我的目标是编写一个程序来计算和存储字符串在字符数组中出现的位置
- 如何为包含头文件的目标编写生成文件?
- 线性优化目标函数中的绝对值
- 制作文件:没有规则来制定目标:如何设置正确的规则?
- 字符串函数在目标C++上运行时C++返回空
- 如何定义自定义生成配置类型,其中通常是.exe的目标改为 DLL
- 请求最简单的 OpenMP 目标 GPU 示例
- LLVM 编译:目标的配方 '../lib/IR/Release+Asserts/Intrinsics.gen.tmp' failed
- 当目标指针不是基类的类型时,为什么允许dynamic_cast为多态类生成 null 指针?
- 我应该如何在没有变量的情况下将相同的参数传递给 CMAKE 中的多个目标?
- CMake 错误 - 目标 foo INTERFACE_SOURCES属性包含在源目录中以前缀为前缀的路径