omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Retrieving the iOS document directory

    Pythonista
    3
    5
    3246
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • marcus67
      marcus67 last edited by

      After a long pause I finally started to work on my Pythonista app Rechtschreibung (see https://github.com/marcus67/rechtschreibung) again. I would like to publish it in the AppStore. As a first step I used the Xcode template to run the Python code in the emulator. I only worked partially. As I found out all the errors were due to the fact that I try to write files located in the bundle directory structure of my app (which is a big no-no in iOS). Instead I have to use the so-called "DocumentDirectory" which is provided by some library functions in Objective C (see e.g. https://stackoverflow.com/questions/4129576/writing-a-string-to-a-text-file-using-xcode-for-iphone-dev). The question is for me how to access these library functions in Pythonista. I would guess that objc_util might help, but none of the identifiers mentioned in the stackoverflow example seem to correspond to Objective C classes. Does anybody have an idea as to how to do this? Thanks a lot!

      1 Reply Last reply Reply Quote 0
      • JonB
        JonB last edited by

        NSHomeDirectory, for example, is a c function -- c.NSHomeDirectory -- but not the recommended way, apparantly. NSFileManager has some methods to get various system folders:

        f=ObjCClass('NSFileManager').defaultManager()
        docpath=str(f.URLsForDirectory_inDomains_(9,1)[0].path())

        http://web.mit.edu/darwin/src/modules/Libc/include/NSSystemDirectories.h has the constants for the two arguments, but basically (9,1) returns Documents folder.

        samaklis 1 Reply Last reply Reply Quote 1
        • samaklis
          samaklis @JonB last edited by

          @JonB Is there a way to “deploy” configuration files/settings in the Documents directory when you are building the project in Xcode?

          Thanks

          1 Reply Last reply Reply Quote 0
          • JonB
            JonB last edited by

            I'd imagine you could copy them in your code?

            samaklis 1 Reply Last reply Reply Quote 0
            • samaklis
              samaklis @JonB last edited by

              @JonB True, that works too. :-) I thought Xcode had some sort of built functionality that is similar to copying bundle resources during the build.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post
              Powered by NodeBB Forums | Contributors