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
-
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! -
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.
-
@JonB Is there a way to “deploy” configuration files/settings in the Documents directory when you are building the project in Xcode?
Thanks
-
I'd imagine you could copy them in your code?
-
@JonB True, that works too. :-) I thought Xcode had some sort of built functionality that is similar to copying bundle resources during the build.