如何在Objective-C的头文件引用C++的头文件
1个回答
展开全部
1.将.m文件扩展名改为.mm,或者修改.m文件的File Type,改为Objective C++ Source.
2.将.h文件File Type改为Objective C++ Preprocessed Source,默认C Header.
[cpp] view plaincopy
//
// PlatformCommon.h
// LibObject
//
// Created by chen yang on 13-3-20.
// Copyright (c) 2013年 admin. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <iostream>
#import <map>
#define NSStringToString(str) (str != nil ? [str UTF8String] : "")
#define StringToNSString(str) [NSString stringWithUTF8String:str.c_str()]
@interface PlatformCommon : NSObject
+ (std::map<std::string, std::string> )NSDictionaryToMap:(NSDictionary *)params;
@end
[cpp] view plaincopy
//
// PlatformCommon.mm
// LibObject
//
// Created by chen yang on 13-3-20.
// Copyright (c) 2013年 admin. All rights reserved.
//
#import "PlatformCommon.h"
#import <iostream>
#import <map>
using namespace std;
@implementation BlcPlatformCommon
+ (std::map<std::string, std::string> )NSDictionaryToMap:(NSDictionary *)params
{
NSArray *allKeys = [params allKeys];
std::map<std::string, std::string> mapParams;
for (NSString *key in allKeys)
{
mapParams[NSStringToString(key)] = NSStringToString([params objectForKey:key]);
}
return mapParams;
}
@end
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询