Skip navigation

How to use NSData and NSBundle together?

682 Views 9 Replies Latest reply: Jan 24, 2013 5:53 PM by red_menace RSS
letatanu Calculating status...
Currently Being Moderated
Jan 23, 2013 7:54 AM

Hi everyone, I have NSData to create a file *.txt and then I read it by using NSBundle, but it do not working correctly. Can anybody help me?

  • red_menace Level 6 Level 6 (14,275 points)
    Currently Being Moderated
    Jan 23, 2013 7:58 AM (in response to letatanu)

    What does "not working correctly" mean?  No one is going to be able to help much without a detailed description of the problem (including the versions of OS and Xcode being used), and relevant details such as code snippets and error logs.

  • red_menace Level 6 Level 6 (14,275 points)
    Currently Being Moderated
    Jan 23, 2013 8:55 AM (in response to letatanu)

    You aren't really trying to write to the application bundle, are you? 

    I'm not familiar with IOS, but take another look at your file create/write methods.

  • xnav Level 5 Level 5 (6,615 points)
    Currently Being Moderated
    Jan 23, 2013 10:01 AM (in response to letatanu)

    writeToFile: returns a BOOL indicating if it was sucessful.  You may want to check.

  • red_menace Level 6 Level 6 (14,275 points)
    Currently Being Moderated
    Jan 24, 2013 7:12 AM (in response to letatanu)

    WriteToFile is successful

     

    You might want to check that - I can't tell what winds up as the write path, but it doesn't look like you are writing to the same file path that you are reading from.  If you are trying to write to the application bundle (where you are reading from) that is not a good idea.  Apart from reading and writing a file, exactly what is it you are wanting to do?

  • red_menace Level 6 Level 6 (14,275 points)
    Currently Being Moderated
    Jan 24, 2013 5:53 PM (in response to letatanu)

    The NSBundle class has some methods for finding resources in the application bundle, if that is where your file is located.  You just need to provide a valid path for your file read/write, wherever that is.  If you are trying to use some kind of preference, look at NSUserDefaults, if you are using one of the standard directories such as the temporary directory, look at NSFileManager, etc.

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.