Problem with using a plist

Discussion in 'iOS Programming' started by TiberiusXavier, May 26, 2010.

  1. TiberiusXavier macrumors member

    Joined:
    Apr 18, 2010
    Location:
    Chicago
    #1
    I am writing an application where I save a favorites list as a .plist file. Without specifying the path, I would think the file is using the application's private Documents area. When I run my app on the simulator (version 3.1.3), the favorites work as expected. However, I load the image on my actual iPhone 3GS, the favorites appear to work, but when I relaunch my app, it seems like the list is missing. Upon adding some logging to debug the problem, the writeToFile operation (not shown in the code below) returns FALSE/NO. Is there a better way to explicitly define the full path to the .plist file?

    SOLVED
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Where does the documentation state that this magically guessing that you want to save in your Documents folder happens? (hint it doesn't say this as that doesn't happen).

    Use the documented function to get the path to your documents folder and the NSString path utilities to append the filename.
     
  3. TiberiusXavier thread starter macrumors member

    Joined:
    Apr 18, 2010
    Location:
    Chicago
    #3
    Thanks for your flippant reply. I really need that this morning. Of course there is no such thing as undocumented functionality.

    After all, just because every Mac, PC, Linux box, Sun station, even OpenVMS have a concept of a current working directory. What was I thinking?

    I decided to use the NSUserDefaults instead. Works fine. Thanks anyway.
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    You are very welcome. I'm glad it's what you need.
     
  5. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    As you are starting to learn, I hope, iPhone OS is not like any of these.
     
  6. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #6
    Whilst this is true the iPhone OS does have a cwd. It's just not silently set to the documents directory for the currently running app. And if it was this would be documented.
     
  7. TiberiusXavier thread starter macrumors member

    Joined:
    Apr 18, 2010
    Location:
    Chicago
    #7
    Indeed. I knew that the simulator may not behave identically to the device. I just didn't anticipate file and directory differences, and I took for granted that the startup path is someplace other than the applications sandbox.
     

Share This Page