Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3352758
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:04:08+00:00 2026-05-18T02:04:08+00:00

I am trying to write a list to a text file that is included

  • 0

I am trying to write a list to a text file that is included in my project (Deck.txt) the relevant code is as follows:

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Deck" ofType:@"txt"];
NSFileHandle *fileHandle = [NSFileHandle fileHandleForWritingAtPath:filePath];
deck = [[NSString alloc]initWithFormat: @"%@\n%@    %@",file, txtQuantity.text, cardName];
//[deck writeToFile:filePath atomically:YES encoding:NSStringEncodingConversionAllowLossy error:nil];
[fileHandle writeData:[deck dataUsingEncoding:NSUTF8StringEncoding]];                   
[fileHandle closeFile];

When I run the code it will not save to the text document however, or at least not the one included in my project. It will still create the list and read from the file all the data that I am trying to write, but when I close the program no changes are made to the text document. Any help would be most appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T02:04:09+00:00Added an answer on May 18, 2026 at 2:04 am

    If you’ve already got your NSData instance, you can certainly just write the data to the built in document directory on the device. With a bit of searching, it’s not hard to find the location when run from the simulator for checking purposes.

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *docDir = [paths objectAtIndex: 0];
    NSString *docFile = [docDir stringByAppendingPathComponent: @"deck.txt"];
    
    //your variable "deck"
    [deck writeToFile: docFile atomically: NO];
    

    This will certainly write to a file in your documents directory. It should only be a matter of altering your code to read from the directory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a macro that will generate a plain-text list of files
I'm trying to write an array (list?) to a text file using Python 3.
I'm trying to write a function that does the following: Given a text file,
im trying to write an app that will display a list off lines from
I'm trying to write a bash script that will process a list of files
I am trying to write a custom script that will keep a list of
I am trying to write a function that will filter a list of tuples
I'm trying to write a merge-sort function that takes a list and a comparison
I am trying to write a code for a linked list but when I
I am trying to write a powershell script that will take in a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.