Xcode,"NavigatingHierarchicalDataUsingOutlineAndSplitViews", and the Apple FileManager?

(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/ "

Answered by DTS Engineer in 683754022

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"

Accepted Answer

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"

Where in Signing & Capabilities in Xcode is the switch to turn SandBoxing for the app off?

I happen to know that you’ve already found the answer to this, but I’m going to respond anyway just in case other folks hit the same issue.

The Signing & Capabilities editor is composed of stacked elements, where each element manages a specific capability. You can operate on each element separately:

  • To add an element, click the “+ Capability” button at the top of the editor.

  • To remove an element, click the X button at the top right of that element.

  • To collapse or uncollapse an element, click the disclosure triangle next to the element name.


Specifically what I want to do is.... /Users/me/somedir/filex -> [application] -> /Users/me/~/Documents/somedir/filex.xyz (in iCould)..... and the inverse where the App performs some operation then stores it under ~/Documents/somedir... then can pull it out [application] -> /Users/me/some_non_iCoud_dir. I'd like to be able to do it with a Tree representation of the files.

I don’t really understand this. I think it’d help if you broke this into its component parts and then asked questions about each part. For example:

  • Parse the file system hierarchy into a set of in-memory nodes.

  • Display those nodes in an outline view.

Beyond that I’m not entire sure because it seems to be related to iCloud and iCloud is a very fuzzy term (it’s a marketing term for a vast array of different underlying technologies).

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Xcode,"NavigatingHierarchicalDataUsingOutlineAndSplitViews", and the Apple FileManager?
 
 
Q