2015-06-07 275 views
1

我正在使用NSBatchUpdateRequest来更新我的核心数据内容。我使用下面的代码:NSBatchUpdateRequest将字符串转换为unicode

NSBatchUpdateRequest *req = [[NSBatchUpdateRequest alloc]initWithEntityName:@"Mostvisited"]; 
    req.propertiesToUpdate = @{@"newsCategory":self.newsCategory,@"newsCommentsCount":self.newsCommentsCount,@"newsDate":self.newsJalaliDate,@"newsID":self.newsID,@"newsLead":self.newsLead,@"newsPhotoLink":self.newsPhotoLarge,@"newsTitle":arr,@"newsType":self.newsType,@"timeStamp":[NSDate date] 
           }; 

    req.resultType = NSUpdatedObjectIDsResultType; 
    NSBatchUpdateResult *result = (NSBatchUpdateResult *)[context executeRequest:req error:nil]; 
    NSLog(@"objects update:%@",result.result); 

所有的更新传递的对象是包含阿拉伯语NSStringNSArray。令人惊讶的是,当我在更新后获取核心数据的内容时,我得到的是Unicode字符串不是阿拉伯数字。

回答

0

字符串默认是Unicode,如果你想让它们成为阿拉伯语,你可能需要使用CFStringTransform来转换它们。有一篇很好的文章详细说明了NSHipster如何实现这一点。

从本质上讲,它的这一呼吁:

CFStringTransform(mutableString, nil, kCFStringTransformToLatin, Boolean(0)) 

更多信息: CFStringTransform

相关问题