Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Dec 15, 2006, 04:36 AM   #1
SkS
macrumors newbie
 
Join Date: Dec 2006
Write to Text-file in Xcode (noob)

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:@"\n"];

Hope you can help me, thanks
- SKS
SkS is offline   0 Reply With Quote
Old Dec 17, 2006, 09:41 PM   #2
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
I think what you want is something like this:

Code:
[barcode writeToFile:@"/file.txt" atomically:YES];
kainjow is offline   0 Reply With Quote
Old Dec 18, 2006, 03:24 AM   #3
Soulstorm
macrumors 68000
 
Soulstorm's Avatar
 
Join Date: Feb 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.
Soulstorm is offline   0 Reply With Quote
Old Dec 18, 2006, 09:30 AM   #4
garethlewis2
macrumors 6502
 
Join Date: Dec 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.
garethlewis2 is offline   0 Reply With Quote
Old Sep 22, 2010, 09:32 PM   #5
sikosis
macrumors newbie
 
Join Date: Sep 2010
Pity writeToFile is deprecated ...
sikosis is offline   0 Reply With Quote
Old Sep 22, 2010, 10:51 PM   #6
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
Quote:
Originally Posted by sikosis View Post
Pity writeToFile is deprecated ...
As the docs say:
Quote:
Use writeToFile:atomically:encoding:error: instead.
kainjow is offline   0 Reply With Quote
Old Sep 22, 2010, 11:05 PM   #7
sikosis
macrumors newbie
 
Join Date: Sep 2010
Ah worked it out ... you need to add a couple of extra params.

Quote:
- (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 :)

Last edited by kainjow; Sep 22, 2010 at 11:27 PM. Reason: merged posts
sikosis is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Passing a text file into Xcode instead of using the command line (C language) hollabit Mac Programming 19 Mar 31, 2014 11:45 AM
Can you write a script to auto delete text messages? bobfitz14 iOS 7 6 Mar 23, 2014 04:26 PM
Anyway to write a script that write text into an existing text file hypmatize Mac Programming 10 Jun 12, 2013 05:52 AM
TxtPub - Text file reader app by converting text to ePub automatically. Ralph Kim iPad Apps 0 Apr 26, 2013 09:13 PM
Trying to Convert nvAlt text file to MS Word .doc file thelucas Mac Applications and Mac App Store 2 Apr 8, 2013 07:59 PM

Forum Jump

All times are GMT -5. The time now is 11:50 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC