存储数据时出现问题
我无法获取我存储的数据......这是代码:
if ([string isEqualToString:@""]) {
//RECUPERO DATA
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *pathToDocuments=[paths objectAtIndex:0];
pathToDocuments=[pathToDocuments stringByAppendingString:@"getSubscriptionsListShowOnlyWithUnreadFeeds.txt"];
NSLog(pathToDocuments);
dataReply=[[NSData alloc] initWithContentsOfFile:pathToDocuments];
NSString *string = [[NSString alloc] initWithData:dataReply encoding:NSASCIIStringEncoding];
NSLog(@"string recuperata %@",string);
}
if ([string isEqualToString:@""]==NO) {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *pathToDocuments=[paths objectAtIndex:0];
pathToDocuments=[pathToDocuments stringByAppendingString:@"getSubscriptionsListShowOnlyWithUnreadFeeds.txt"];
NSLog(pathToDocuments);
[dataReply writeToFile:pathToDocuments atomically:YES];}
有什么问题吗?
编辑 没有错误,没有崩溃,但是 NSLog(@"string recuperata %@",string);
打印一个空字符串! (数据存储在设备中,因为当字符串!=空时我至少运行过一次我的应用程序 谢谢
I can't getting my stored data.... This is the code:
if ([string isEqualToString:@""]) {
//RECUPERO DATA
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *pathToDocuments=[paths objectAtIndex:0];
pathToDocuments=[pathToDocuments stringByAppendingString:@"getSubscriptionsListShowOnlyWithUnreadFeeds.txt"];
NSLog(pathToDocuments);
dataReply=[[NSData alloc] initWithContentsOfFile:pathToDocuments];
NSString *string = [[NSString alloc] initWithData:dataReply encoding:NSASCIIStringEncoding];
NSLog(@"string recuperata %@",string);
}
if ([string isEqualToString:@""]==NO) {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *pathToDocuments=[paths objectAtIndex:0];
pathToDocuments=[pathToDocuments stringByAppendingString:@"getSubscriptionsListShowOnlyWithUnreadFeeds.txt"];
NSLog(pathToDocuments);
[dataReply writeToFile:pathToDocuments atomically:YES];}
Is there something wrong?
EDIT
No bugs no crashes but the NSLog(@"string recuperata %@",string);
prints an empty string! (data are stored in the device because I had running at least one time my app when string!= empty
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为第二个 if 缺少 else 。我不确定这是否是您想要的,或者是否是您的拼写错误。检查这是否是问题所在。
I think there is a else missing on the second if. I'm not sure if that is what you wanted or if it is a typo on your part. check if that is the problem.
如果您不确定编码,请尝试更改为
NSUTF8StringEncoding
,通常它可以工作。Try changing to
NSUTF8StringEncoding
if you are unsure about the encoding, usually it works.