Skip to content

Commit e1c2bbf

Browse files
committed
better use of FileManager
1 parent 6bddf3b commit e1c2bbf

File tree

11 files changed

+19
-19
lines changed

11 files changed

+19
-19
lines changed

bk1ch03p069computedVariables/bk1ch03p069computedVariables/ViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class ViewController: UIViewController {
7171
}
7272
get {
7373
if _myBigData == nil {
74-
let fm = FileManager()
74+
let fm = FileManager.default
7575
let f = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("myBigData")
7676
if let d = try? Data(contentsOf:f) {
7777
print("loaded big data from disk")

bk1ch04p204arrays/bk1ch04p204collections/ViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ class ViewController: UIViewController {
541541
do {
542542
// showing one common way to lose element typing
543543
let arr = [1,2,3]
544-
let fm = FileManager()
544+
let fm = FileManager.default
545545
let f = fm.temporaryDirectory.appendingPathComponent("test.plist")
546546
(arr as NSArray).write(to: f, atomically: true)
547547
let arr2 = NSArray(contentsOf: f)

bk2ch06p336memoryWarning/ch19p647memoryWarning/ViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class ViewController : UIViewController {
5353
}
5454
get {
5555
if _myBigData == nil {
56-
let fm = FileManager()
56+
let fm = FileManager.default
5757
let f = URL(fileURLWithPath: NSTemporaryDirectory())
5858
.appendingPathComponent("myBigData")
5959
if let d = try? Data(contentsOf:f) {

bk2ch23p798basicFileOperations/ch36p1053basicFileOperations/ViewController.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class ViewController: UIViewController {
1919

2020
@IBAction func doButton2 (_ sender: Any!) {
2121
do {
22-
let fm = FileManager()
22+
let fm = FileManager.default
2323
let docsurl = try fm.url(for:.documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
2424
print(docsurl)
2525
} catch {
@@ -29,7 +29,7 @@ class ViewController: UIViewController {
2929

3030
@IBAction func doButton3 (_ sender: Any!) {
3131
do {
32-
let fm = FileManager()
32+
let fm = FileManager.default
3333
let suppurl = try fm.url(for:.applicationSupportDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
3434
print(suppurl)
3535
} catch {
@@ -39,7 +39,7 @@ class ViewController: UIViewController {
3939

4040
@IBAction func doButton4 (_ sender: Any!) {
4141
do {
42-
let fm = FileManager()
42+
let fm = FileManager.default
4343
let docsurl = try fm.url(for:.documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
4444
let myfolder = docsurl.appendingPathComponent("MyFolder")
4545

@@ -57,7 +57,7 @@ class ViewController: UIViewController {
5757

5858
@IBAction func doButton5 (_ sender: Any!) {
5959
do {
60-
let fm = FileManager()
60+
let fm = FileManager.default
6161
let docsurl = try fm.url(for:.documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
6262
let arr = try fm.contentsOfDirectory(at:docsurl, includingPropertiesForKeys: nil)
6363
arr.forEach{print($0.lastPathComponent)}
@@ -73,7 +73,7 @@ class ViewController: UIViewController {
7373

7474
@IBAction func doButton7 (_ sender: Any!) {
7575
do {
76-
let fm = FileManager()
76+
let fm = FileManager.default
7777
let docsurl = try fm.url(for:.documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
7878
let dir = fm.enumerator(at:docsurl, includingPropertiesForKeys: nil)!
7979
for case let f as URL in dir where f.pathExtension == "txt" {
@@ -88,7 +88,7 @@ class ViewController: UIViewController {
8888

8989
@IBAction func doButton8 (_ sender: Any!) {
9090
do {
91-
let fm = FileManager()
91+
let fm = FileManager.default
9292
let docsurl = try fm.url(for:.documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
9393
let moi = Person(firstName: "Matt", lastName: "Neuburg")
9494
let moidata = NSKeyedArchiver.archivedData(withRootObject: moi)
@@ -132,7 +132,7 @@ class ViewController: UIViewController {
132132

133133
@IBAction func doButton9 (_ sender: Any!) {
134134
do {
135-
let fm = FileManager()
135+
let fm = FileManager.default
136136
let docsurl = try fm.url(for:.documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
137137
let moifile = docsurl.appendingPathComponent("moi.txt")
138138
switch which {

bk2ch23p802fileHandoff/ch36p1060fileHandoff/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class AppDelegate : UIResponder, UIApplicationDelegate {
2828
if dir == "Inbox" {
2929
do {
3030
print("inbox")
31-
let fm = NSFileManager()
31+
let fm = FileManager.default
3232
let docsurl = try fm.URLForDirectory(.DocumentDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: false)
3333
let dest = docsurl.URLByAppendingPathComponent(url.lastPathComponent!)
3434
print("copying")

bk2ch23p802fileHandoff/ch36p1060fileHandoff/ViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ViewController: UIViewController, UIDocumentInteractionControllerDelegate,
2121
func locateDoc () -> URL? {
2222
var url : URL? = nil
2323
do {
24-
let fm = FileManager()
24+
let fm = FileManager.default
2525
let docsurl = try fm.url(for:.documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
2626
let dir = fm.enumerator(at: docsurl, includingPropertiesForKeys: nil)!
2727
for case let f as URL in dir {
@@ -89,7 +89,7 @@ class ViewController: UIViewController, UIDocumentInteractionControllerDelegate,
8989
@IBAction func doPreviewMultipleUsingQuickLook (_ sender: Any!) {
9090
self.docs = [URL]()
9191
do {
92-
let fm = FileManager()
92+
let fm = FileManager.default
9393
let docsurl = try fm.url(for:.documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
9494
let dir = fm.enumerator(at: docsurl, includingPropertiesForKeys: nil)!
9595
for case let f as URL in dir {

bk2ch23p809peopleGroups/ch36p1066peopleGroups/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
2222
// NB should start by asking for the file manager's ubiquityIdentityToken
2323
// if it doesn't exist, there is no iCloud account
2424
DispatchQueue.global(qos:.default).async {
25-
let fm = FileManager()
25+
let fm = FileManager.default
2626
let ubiq = fm.url(forUbiquityContainerIdentifier:nil)
2727
print("ubiq: \(ubiq)")
2828
DispatchQueue.main.async {

bk2ch23p809peopleGroups/ch36p1066peopleGroups/DocumentLister.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class DocumentLister: UITableViewController {
1111
return ubiq
1212
} else {
1313
do {
14-
let fm = FileManager()
14+
let fm = FileManager.default
1515
return try fm.url(for:.documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
1616
} catch {
1717
print(error)
@@ -35,7 +35,7 @@ class DocumentLister: UITableViewController {
3535
func doRefresh (_: Any?) {
3636
print("refreshing")
3737
do {
38-
let fm = FileManager()
38+
let fm = FileManager.default
3939
self.files = try fm.contentsOfDirectory(at: self.docsurl, includingPropertiesForKeys: nil).filter {
4040
print($0)
4141
if fm.isUbiquitousItem(at:$0) {

bk2ch23p809peopleGroups/ch36p1066peopleGroups/PeopleLister.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class PeopleLister: UITableViewController, UITextFieldDelegate {
3030

3131
self.tableView.register(UINib(nibName: "PersonCell", bundle: nil), forCellReuseIdentifier: "Person")
3232

33-
let fm = FileManager()
33+
let fm = FileManager.default
3434
self.doc = PeopleDocument(fileURL:self.fileURL)
3535

3636
func listPeople(_ success:Bool) {

bk2ch23p821SQLite/ch36p1077SQLite/ViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ViewController: UIViewController {
1616
@IBAction func doButton (_ sender: Any!) {
1717

1818
do {
19-
let fm = FileManager()
19+
let fm = FileManager.default
2020
try fm.removeItem(atPath:self.dbpath) // in case we did this once already
2121
} catch {}
2222

0 commit comments

Comments
 (0)