(1) Hi All, I'm a bit of a newbie to Apple, but have used FreeBSD/Linux so I'm somewhat familiar with it's file systems and access with C, C++, and TclTk. I'm really trying to wrap my head around the "Apple FileManager" but find the documentation difficult without the best of examples. Are there any good books out on Xcode, Apple Foundation usage (FileManager) and the NSFileSystem?, etc? Or how to even read and understand Apple's Developer Documents?
Thanks to Quinn (The Eskimo), for replying on Swift Forum, he suggested I follow up here, and he gave me some good pointers on Docs to read. I believe now the below question is due to attributes of "Sandboxing". Since I knew MacOS was BSD underneath, I'd used a Terminal and created other directories other than just the "recommended". While playing with Xcode, I noticed if I used MacOS, "Command Line" and complile a File enumerator from "let directoryURL = URL(fileURLWithPath: "/Users/me/Documents/MyFolder")" I get it asking do I want to give it permission to view my "MyFolder". If I set up a "MacOS, App, and use the same code it fails and I see no asking permission box come up. **Is there a way to give specific access/Entitlements to folders under /Users/me/folders to the/an Xcode app I'm working on? ** The below "NDUOASV" demo code from Apple is what has led me down this path.... If I drop the folders from Finder into the NDUOASV app, it works.
(2) Does anyone out there have experience with "NavigatingHierarchicalDataUsingOutlineAndSplitViews" in the Apple docs. If so please read the following. I've been playing with it to try and help understand the Apple File System and usage. I've put in a print("debug", url) in the function func addFileSystemObject(_ url: URL, indexPath: IndexPath) { In the code, I've located where they load a default example directory for viewing in their app in their file "OutlineViewController.swift". The code is let appsURLs = FileManager.default.urls(for: .applicationDirectory, in: .localDomainMask) addFileSystemObject(appsURLs[0], indexPath: IndexPath(indexes: [0, 0])) It does as expected. The file URL is " debug file:///Applications/". However when I change the directory such as let docsURLs = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask) addFileSystemObject(docsURLs[0], indexPath: IndexPath(indexes: [0, 0])) I would of expected it locating my Documents Directory (which is iClouded) under my user directory. Instead it creates a directory... "debug print file:///Users/me/Library/Containers/com.example.apple-samplecode.SourceViewMD7FZBNW84/Data/Documents/" I believe the demo app is sandboxing me correct? But when I drag and drop a folder from my user documents directory into the app from finder it's "debug result is... " debug file:///Users/me/Documents/MyFolder/ "
So, let’s tackle your first question first. You wrote:
I believe now the below question is due to attributes of "Sandboxing".
Correct. Keep in mind that the App Sandbox is optional for Mac apps — unless you plan to ship via the Mac App Store, where it’s required — so the easiest option here is to simply disable the sandbox. You can do this in Xcode’s Signing & Capabilities editor.
However, that’s not the end of the story. macOS 10.15 extended mandatory access control to the user’s Documents folder, so accessing that will trigger a MAC alert. See On File System Permissions for more.
Finally, for any of this to work you must sign your app with a stable code signing identity. IF your code is unsigned, or ad hoc signed, displayed in Xcode as “Sign to run locally”, the system can’t determine that version N+1 of your app is the same as version N, and so can’t track persistent access to things like the Documents folder.
If you have a paid developer account, sign with an Apple Development identity created under that account. If you don’t have a paid developer account, use your Apple ID as a Personal Team.
ps DevForums supports Markdown for formatting and I encourage you to use that to make it easier to read your posts.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"