Skip to content

Commit db7f89d

Browse files
authored
📖 Updated README
Improved a few not so clear comments and code snippets.
1 parent d041e0a commit db7f89d

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

README.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# 📁 LSFileWrapper
22
Replacement for NSFileWrapper that loads / saves content on-demand. Understands how to save / serialize objects like NSData, UIImage, NSImage, NSDictionary, etc...
3+
34
## 💻 Requirements
45
LSFileWrapper works on Mac OS X 10.7+ and iOS 8.0 or newer. The Xcode project contains two framework targets for:
56
* 💻 macOS (10.7 or greater)
67
* 📱 iOS (8.0 or greater)
8+
79
## 📖 Usage
810
* [Creating new wrappers](#creating-new-wrappers)
911
* [Loading from disk](#loading-from-disk)
@@ -13,6 +15,7 @@ LSFileWrapper works on Mac OS X 10.7+ and iOS 8.0 or newer. The Xcode project co
1315
- [Updating contents](#updating-contents)
1416
* [Removing wrappers](#removing-wrappers)
1517
* [Getting child wrappers](#getting-child-wrappers)
18+
1619
### Creating new wrappers
1720
To create a new LSFileWrapper use `-initDirectory` for directory wrappers or `-initFile` for regular file wrappers.
1821
These wrappers and all of their contents will be stored entirely in the memory until any of the write methods gets called.
@@ -42,7 +45,7 @@ let url: URL
4245
let existingWrapper = LSFileWrapper(with: url, isDirectory: false)
4346
```
4447
### Writing to disk
45-
> **_Notice:_** Writing methods should only be called on a wrapper that has no parents.
48+
> **_Notice:_** Writing methods should only be called on the top most wrapper – a wrapper that has no parents.
4649
4750
To write the wrapper to disk call `-writeToURL` or `-writeUpdatesToURL`, the difference between the two being that updates will update the cached wrapper location and remove changes from memory, so use this only in situations like autosave. For duplicate operations use `-writeToURL`. Only the main wrapper can be written to disk – the wrapper that has no parents. If the write is issued as part of NSDocument's save routine there's a convenience method `-writeToURL forSaveOperation` that automatically calls `-writeToURL` or `-writeUpdatesToURL` based on save operation and also handles document backups (versioning) and url switches on save as.
4851
```objective-c
@@ -56,7 +59,7 @@ NSURL* url;
5659
// otherwise the write method could result in partial contents on the disk and potential loss of data.
5760
[mainWrapper writeUpdatesToURL: url];
5861
```
59-
*NSDocument:*
62+
*NSDocument (macOS only):*
6063
```objective-c
6164
LSFileWrapper* mainWrapper;
6265
@@ -81,7 +84,7 @@ mainWrapper.write(to: url)
8184
mainWrapper.writeUpdates(to: url)
8285
```
8386

84-
*NSDocument:*
87+
*NSDocument (macOS only):*
8588
```swift
8689
let mainWrapper: LSFileWrapper
8790

@@ -92,21 +95,21 @@ override func write(to url: URL, for saveOperation: SaveOperationType, originalC
9295
}
9396
```
9497
### Adding contents
95-
> **_Notice:_** For directory wrappers only.
98+
> **_Notice:_** Directory wrappers only.
9699
97100
To add a file wrapper to an existing directory wrapper use `-addFileWrapper` or `-setFileWrapper`, the difference between the two being that *add* will suffix a filename with 2, 3, 4, etc… if the wrapper with the same name already exists and return the final filename, *set* will overwrite any existing file wrappers.
98101
`-addContent` and `-setContent` work the same way, but create the file wrapper for you.
99102
```objective-c
100103
LSFileWrapper* directoryWrapper;
101104

102105
// Adds an empty directory with preferred name
103-
NSString* fileName = [directoryWrapper addFileWrapper: [[LSFileWrapper alloc] initDirectory] withFilename: @"Empty Directory Name"];
106+
NSString* folderName = [directoryWrapper addFileWrapper: [[LSFileWrapper alloc] initDirectory] withFilename: @"Empty Directory Name"];
104107

105108
// Adds and overrides any wrappers matching the filename
106109
[directoryWrapper setFileWrapper: [[LSFileWrapper alloc] initDirectory] withFilename: @"Empty Directory Name"];
107110

108111
// Adds a new text file
109-
[directoryWrapper addContent: @"Hello, World!" withFilename: @"hello.txt"];
112+
NSString* fileName = [directoryWrapper addContent: @"Hello, World!" withFilename: @"hello.txt"];
110113

111114
// Adds and overrides any files matching the filename. This method could also be used when changes are made to the file
112115
[directoryWrapper setContent: @"Hello, World!" withFilename: @"hello.txt"];
@@ -117,19 +120,19 @@ NSString* fileName = [directoryWrapper addFileWrapper: [[LSFileWrapper alloc] in
117120
let directoryWrapper: LSFileWrapper
118121
119122
// Adds an empty directory with preferred name
120-
let fileName = directoryWrapper.addFileWrapper(LSFileWrapper(directory: ()) withFilename: "Empty Directory Name")
123+
let folderName = directoryWrapper.addFileWrapper(LSFileWrapper(directory: ()) withFilename: "Empty Directory Name")
121124
122125
// Adds and overrides any wrappers matching the filename
123126
directoryWrapper.setFileWrapper(LSFileWrapper(directory: ()) withFilename: "Empty Directory Name")
124127
125128
// Adds a new text file. Content has to be of Objective-C type, i.e. NSString, NSData... or casted with `as` operator
126-
directoryWrapper.addContent(NSString("Hello, World!"), withFilename: "hello.txt")
129+
let filename = directoryWrapper.addContent(NSString("Hello, World!"), withFilename: "hello.txt")
127130
128131
// Adds and overrides any files matching the filename. This method can be used when changes are made to the file
129132
directoryWrapper.setContent("Hello, World!" as NSString, withFilename: "hello.txt")
130133
```
131134
### Reading Contents
132-
> **_Notice:_** For file wrappers only.
135+
> **_Notice:_** File wrappers only.
133136
134137
To retrieve contents of a regular file wrapper use one of various convenience methods: `-data`, `-string`, `-dictionary`, `-image`.
135138
```objective-c
@@ -147,7 +150,7 @@ let optionalData = fileWrapper.data()
147150
let optionalString = fileWrapper.string()
148151
```
149152
### Updating Contents
150-
> **_Notice:_** For file wrappers only.
153+
> **_Notice:_** File wrappers only.
151154
152155
To update the contents of a regular file wrapper use `-updateContent`.
153156
```objective-c
@@ -163,7 +166,7 @@ let fileWrapper: LSFileWrapper
163166
fileWrapper.updateContent("Hello, World!" as NSString)
164167
```
165168
### Removing wrappers
166-
> **_Notice:_** For directory wrappers only.
169+
> **_Notice:_** Directory wrappers only.
167170
168171
To remove a file wrapper from existing wrapper use `-removeFileWrapper`.
169172
```objective-c
@@ -186,7 +189,7 @@ if let wrapperToRemove = directoryWrapper.withPath("hello.txt") {
186189
}
187190
```
188191
### Getting child wrappers
189-
> **_Notice:_** For directory wrappers only.
192+
> **_Notice:_** Directory wrappers only.
190193
191194
To get wrappers from a directory wrapper use `@property fileWrappers` or call `-fileWrapperWithPath`, the latter will also traverse all children based on path.
192195
```objective-c

0 commit comments

Comments
 (0)