iOS 开发实用技术导航
NSHipster 中文版
› http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
› http://www.cocos2d-iphone.org/
CocoaPods
› http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
› http://code.google.com/mobile/analytics/
WWDC
› https://developer.apple.com/wwdc/
Design Guides and Resources
› https://developer.apple.com/design/
Transcripts of WWDC sessions
› http://asciiwwdc.com
Cocoa with Love
› http://cocoawithlove.com/
Cocoa Dev Central
› http://cocoadevcentral.com/
NSHipster
› http://nshipster.com/
Style Guides
› Google Objective-C Style Guide
› NYTimes Objective-C Style Guide
Useful Tools and Services
› Charles Web Debugging Proxy
› Smore
GhXst
V2EX  ›  iDev

新手问个iphone程序的问题,困扰了很久了

  •  
  •   GhXst · Nov 29, 2011 · 4833 views
    This topic created in 5467 days ago, the information mentioned may be changed or developed.
    paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    documentsDirectory = [paths objectAtIndex:0];
    fileName = [NSString stringWithFormat:@"%@/File.txt", documentsDirectory];
    [self.data writeToFile:fileName atomically:NO];
    其中
    self.data的类型为NSMutableArray,用NSLog能看到self.data的内容,fileName也有,atomically:YES和NO都试了。程序没有报错,但是运行完打开指定文件夹没有文件生成,会是什么问题?
    5 replies  •  1970-01-01 08:00:00 +08:00
    GhXst
    GhXst
    OP
    Nov 29, 2011
    1
    没有人帮忙吗?还是我提供的信息不够全啊?
    GhXst
    GhXst
    OP
    Nov 29, 2011
    2
    好了,已经解决了,写文件成功,就是有些乱码,再调整了
    [NSKeyedArchiver archiveRootObject:self.data toFile:fileName];
    Livid
    Livid
    MOD
    PRO
    Nov 29, 2011
    3
    NSMutableArray 有 writeToFile:atomically: 这个方法么?
    keakon
    keakon
    Nov 30, 2011
    4
    @GhXst 乱码和coder有关,只要你载入没问题,就不用管乱码了。拼接路径可以用stringByAppendingPathComponent:。
    GhXst
    GhXst
    OP
    Nov 30, 2011
    5
    @keakon 想不到一个小小的问题惊动老大了!测试如下:
    paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    documentsDirectory = [paths objectAtIndex:0];
    fileName = [NSString stringWithFormat:@"%@/File.txt", documentsDirectory];
    NSMutableArray* test = [[NSMutableArray alloc] init];
    NSString* a = @"This is a test a!";
    NSString* b = @"This is a test b!";
    [test addObject:a];
    [test addObject:b];
    [test writeToFile:fileName atomically:YES];

    输出文件成功,文件内容如下:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <array>
    <string>This is a test a!</string>
    <string>This is a test b!</string>
    </array>
    </plist>
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4430 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 08:06 · PVG 16:06 · LAX 00:06 · JFK 03:06
    ♥ Do have faith in what you're doing.