将UTF8字符串转换为数组

时间:2014-02-22 17:55:37

标签: ios objective-c utf-8 hebrew

我转换希伯来字符串并尝试将其添加到数组中,这是代码:

 NSMutableArray * myarray;

    // @property(strong,nonatomic) NSMutableArray *stringArray;
    for (NSString * item in stringArray) {

        NSData * UTF8 = [item dataUsingEncoding:NSUTF8StringEncoding];

        NSString * myString = [[NSString alloc] initWithData:UTF8 encoding:NSUTF8StringEncoding];

        NSLog(@"myString = %@",myString); // Hebrew str log fine

        [myarray addObject:myString];

    }

    NSString * ConvetData = [NSString stringWithFormat:@"%@",myarray];

    NSLog(@"ConvetData = %@",ConvetData); // null

    newitem.ingredient = ConvetData;

数组输出为null,如何从转换数据中创建一个字符串?

1 个答案:

答案 0 :(得分:0)

您需要初始化myarrayNSMutableArray *myarray =[[NSMutableArray alloc] init];