Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

SkS

macrumors newbie
Original poster
Dec 15, 2006
1
0
Hi
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
 
I think what you want is something like this:

Code:
[barcode writeToFile:@"/file.txt" atomically:YES];
 
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.
 
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.
 
Ah worked it out ... you need to add a couple of extra params.

- (BOOL)writeToFile:(NSString *)path atomically:(BOOL)useAuxiliaryFile encoding:(NSStringEncoding)enc error:(NSError **)error

@kainjow ... yep that's it -- guess I should have refreshed this page first before replying :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.