Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Learning how to use Xcode / interface builder to program in c/++ furycd001 Mac Programming 6 Sep 20, 2011 04:45 AM
i made this c++ in visual studio... how can i get it to work in xcode DaKyd55 Mac Programming 7 Apr 22, 2011 07:31 AM
Not able to write to file in Xcode with C++ kristianmoss Mac Programming 8 Mar 17, 2011 04:50 PM
Best way to write to NTFS in OS X Dozerrox OS X 3 Jun 29, 2010 12:39 AM
Unable to write to NFS in finder, ok in shell costabunny Mac OS X Server, Xserve, and Networking 16 Jan 21, 2010 06:19 AM


All times are GMT -5. The time now is 04:17 AM.

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

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