Write to Text-file in Xcode (noob)

Discussion in 'Mac Programming' started by SkS, Dec 15, 2006.

  1. SkS
    macrumors newbie

    Dec 15, 2006
    I dont know alot about programming i only know a little about Visual Basic Express and this is Xcode stuff.....

    I have looked at the codes from Bruji's barcode scanner at http://www.bruji.com/cocoa/barcode.html and i now the barcodes is beeing written to a text windows inside the app but i want the app to write the Barcode to a text file on my harddisk.

    If iam right the following codes add the Barcode to the Text window inside the application:

    - (void)gotBarcode:(NSString *)barcode {
    [resultsTextView replaceCharactersInRange:NSMakeRange([[resultsTextView string] length] ,0) withString:barcode];
    [resultsTextView replaceCharactersInRange:NSMakeRange([[resultsTextView string] length],0) withString:mad:"\n"];

    Hope you can help me, thanks
    - SKS
  2. Moderator emeritus


    Jun 15, 2000
    I think what you want is something like this:

    [barcode writeToFile:@"/file.txt" atomically:YES];
  3. macrumors 68000


    Feb 1, 2005
    the barcode is an NSString. So, you can open the developer documentation in your XCode and search the NSString class explanation. In there you will find ways to write an NSString to a file, loading an NSString from a file, and many more.
  4. macrumors 6502

    Dec 6, 2006
    Before you really get yourself into a pickle, buy the following books

    Programming in Objective-C by Stephen Cochan
    Programming Cocoa by Aaron Hillegrass. <Hyped but good, glosses over controllers>
    Cocoa - Anguish, et al. The def book on understanding Cocoa from a programmers point of view, very very heavy, but worth it. Only downside is, it is based on Jaguar code.

    Without that grounding, you will always always get stuck.

    For your question. Look at the docmentation for NSFileHandle and NSFileManager. These aren't the only ways, but they are conveniant and better. safe.
  5. macrumors newbie

    Sep 22, 2010
  6. Moderator emeritus


    Jun 15, 2000
    As the docs say:
  7. macrumors newbie

    Sep 22, 2010
    Ah worked it out ... you need to add a couple of extra params.

    @kainjow ... yep that's it -- guess I should have refreshed this page first before replying :)

Share This Page