I got my entire codebase on GitHub, I get the files from the users
@Environment(\.importFiles).
Code Block swift| file(multipleOfType: [.audio]) { result in |
| switch result { |
| case .success(let urls): |
| openSong (urls: urls) |
| break |
| case .failure(let error): |
| print(error) |
| break |
| case .none: |
| print("No item was selected") |
| } |
| } |
GitHubBecause of the weird issue I got from the bookmark thing, I've refactored it so I don't get the URL from the bookmark immediately after. But there's still issues reading the file it seems, which I'm debugging further. (This doesn't return
Future<Song, SongError>{ $0(.failure(.coundtReadFile)) } weirdly enough
Code Block swift| func load(url: URL, bookmark: Data) throws -> Future<Song, SongError> { |
| var loaded: (URL?, Error?) = (nil, nil) |
| let coordinator = NSFileCoordinator() |
| url.coordinatedRead(coordinator) { inputURL,inputError in |
| loaded = (inputURL, inputError) |
| } |
| guard let loadURL = loaded.0 else { return Future<Song, SongError>{ $0(.failure(.coundtReadFile)) } } |
| |
| return Future<Song, SongError> { promise in |
| self.threadPool.start() |
| let loaded = self.asyncLoad(url: loadURL, bookmark: bookmark) |
| loaded.whenSuccess { song in |
| promise(.success(song)) |
| } |
| loaded.whenFailure { error in |
| print(error) |
| promise(.failure(.coundtReadFile)) |
| } |
| } |
| } |
GitHubThis function could also be important if you're curious how I get the bookmark.
Code Block swift| func add(url: URL) { |
| container.performBackgroundTask { [self] context in |
|
| do { |
| let newSong = Songs(context: context) |
|
| let bookmark = try url.bookmarkData() |
|
| newSong.bookmark = bookmark |
|
| fetchSong(url: url, bookmark: bookmark) |
| } catch { |
| print("An error occured: \(error)") |
| } |
| try? context.save() |
| } |
| } |
GitHubI see you use the document in the apps sandboxing, which I don't do, so I assume that I did something wrong in requesting access for files outside my apps sandboxing?
Cheers, Bastian Inuk Christensen