Last active
April 30, 2023 12:28
-
-
Save beyzaince/8053d16374c3a2e7902c9d11a9dd4ffd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func selectDirectory() { | |
| let panel = NSOpenPanel() | |
| panel.message = "Choose your project directory" | |
| panel.prompt = "Grant permission" | |
| panel.allowsOtherFileTypes = false | |
| panel.canChooseFiles = false | |
| panel.canChooseDirectories = true | |
| panel.directoryURL = projectPath | |
| if panel.runModal() == NSApplication.ModalResponse.OK { | |
| bookmark(panel.url) | |
| givePermissionText = "Please enable MockoloApp in System Settings -> Extensions. After that, you can use in Xcode as an Extension." | |
| } | |
| } | |
| func bookmark(_ url: URL?) { | |
| guard let url = url else { return } | |
| do { | |
| let bookmark = try url.bookmarkData( | |
| options: [], | |
| includingResourceValuesForKeys: nil, | |
| relativeTo: nil | |
| ) | |
| setTemporaryBookmark(bookmark, forURL: url) | |
| } catch { | |
| NSAlert(error: error).runModal() | |
| } | |
| } | |
| func setTemporaryBookmark(_ bookmark: Data, forURL url: URL) { | |
| let temporaryBookmarkKey = "bookmarks.temporary" | |
| var userDefaults = UserDefaults(suiteName: "group.teamIdentifier.com.example.mockoloGroup")! | |
| var temporaryBookmarks: [String: Data] { | |
| return userDefaults.dictionary(forKey: temporaryBookmarkKey)? | |
| .compactMapValues { $0 as? Data } ?? [:] | |
| } | |
| var bookmarks = temporaryBookmarks | |
| bookmarks[url.path] = bookmark | |
| userDefaults.set(bookmarks, forKey: temporaryBookmarkKey) | |
| userDefaults.synchronize() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment