How to write in a txt-file, iOS 7

后端 未结 1 2007
谎友^
谎友^ 2021-01-23 19:22

I\'m trying to make an iPhone app, for iOS 7. I\'ve created a txt file in my project, and want to be able to write the text from the txt file, when I push the write-button, writ

1条回答
  •  一生所求
    2021-01-23 20:19

    You can use the following function :

    -(void) writeToTextFile
    {
        NSArray *paths = NSSearchPathForDirectoriesInDomains
            (NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
    
        NSString *fileName = [NSString stringWithFormat:@"%@/textfile.txt", 
                                                      documentsDirectory];
        NSString *content = @"Your Desired Content";
        [content writeToFile:fileName 
                         atomically:NO 
                               encoding:NSStringEncodingConversionAllowLossy 
                                      error:nil];
    
    }
    

    0 讨论(0)
提交回复
热议问题