文字列キーを使用してオブジェクトを格納したいNSMutableDictionary
ので、次のように宣言しました。
[m_pMsgIdToStructMap setObject:pStruct
forKey:[NSMutableString stringWithString:pStruct->szAsciiName]];
szAsciiName
NSMutableString *
.h ファイルのように宣言されています。警告やエラーは出ていませんが、自分が行っている宣言が正しいかどうかを確認したいです。
編集:
やあ、
main.m
-------
#import <Foundation/Foundation.h>
#import "string.h"
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
stringss* stringsss = [[stringss alloc]init];
//NSMutableString* strs = [[NSMutableString alloc]initWithFormat:"First"];
[stringsss trail:@"First"]; //getting warning:Passing argument 1 of 'trail' from incompatible pointer type
[pool drain];
return 0;
}
stringss.h
----------
#import <Foundation/Foundation.h>
typedef struct
{
int a;
int b;
NSMutableString* szAsciiName;
}st;
@interface stringss : NSObject {
NSMutableDictionary* m_map;
}
-(void)trail:(const char*)szAsciiName;
@end
stringss.m
---------
#import "string.h"
@implementation stringss
-(id)init
{
if (self = [super init]) {
m_map = [[NSMutableDictionary alloc]init];
//pStruct->szAsciiName = [[NSMutableString alloc]init];
}
return self;
}
-(void)trail:(NSString*)szAsciiName
{
st* pStruct = malloc(sizeof(st));
st* pStruct1 = malloc(sizeof(st));
pStruct->a = 10;
pStruct->b = 20;
pStruct->szAsciiName = [[NSMutableString alloc]init];
pStruct->szAsciiName = (NSMutableString*)szAsciiName;
[m_map setObject:(void*)pStruct forKey:szAsciiName];
pStruct1 = (st*)[[m_map objectForKey:szAsciiName]bytes];
}
@end
EXC_BAD_ACCESS 例外も発生しています。