Skip to content

Instantly share code, notes, and snippets.

@christianselig
Created January 8, 2025 16:39
Show Gist options
  • Save christianselig/09cbd7a92ee2912ae03f81b828c0f9e0 to your computer and use it in GitHub Desktop.
Save christianselig/09cbd7a92ee2912ae03f81b828c0f9e0 to your computer and use it in GitHub Desktop.
// Create from App Group ❌
// let appGroupID = "group.com.christianselig.testing"
// let containerURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroupID)!
// let directoryURL = containerURL.appending(path: "testfolder")
// Create from documents directory ✅
let containerURL = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
let directoryURL = containerURL.appending(path: "testfolder")
if !FileManager.default.fileExists(atPath: directoryURL.path) {
try! FileManager.default.createDirectory(at: directoryURL, withIntermediateDirectories: true, attributes: nil)
}
let fileURL = directoryURL.appending(path: "tropy", directoryHint: .notDirectory)
try! "hihowareyou".write(to: fileURL, atomically: true, encoding: .utf8)
// In BOTH cases it even writes the file correctly and can be read! 🫨
print("Contents: \(try! String(contentsOf: fileURL, encoding: .utf8))")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment