You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+15-12Lines changed: 15 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,11 @@
1
1
# 📁 LSFileWrapper
2
2
Replacement for NSFileWrapper that loads / saves content on-demand. Understands how to save / serialize objects like NSData, UIImage, NSImage, NSDictionary, etc...
3
+
3
4
## 💻 Requirements
4
5
LSFileWrapper works on Mac OS X 10.7+ and iOS 8.0 or newer. The Xcode project contains two framework targets for:
5
6
* 💻 macOS (10.7 or greater)
6
7
* 📱 iOS (8.0 or greater)
8
+
7
9
## 📖 Usage
8
10
*[Creating new wrappers](#creating-new-wrappers)
9
11
*[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
To create a new LSFileWrapper use `-initDirectory` for directory wrappers or `-initFile` for regular file wrappers.
18
21
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
42
45
let existingWrapper = LSFileWrapper(with: url, isDirectory: false)
43
46
```
44
47
### 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.
46
49
47
50
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.
48
51
```objective-c
@@ -56,7 +59,7 @@ NSURL* url;
56
59
// otherwise the write method could result in partial contents on the disk and potential loss of data.
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.
98
101
`-addContent` and `-setContent` work the same way, but create the file wrapper for you.
let filename = directoryWrapper.addContent(NSString("Hello, World!"), withFilename: "hello.txt")
127
130
128
131
// Adds and overrides any files matching the filename. This method can be used when changes are made to the file
129
132
directoryWrapper.setContent("Hello, World!" as NSString, withFilename: "hello.txt")
130
133
```
131
134
### Reading Contents
132
-
> **_Notice:_**For file wrappers only.
135
+
> **_Notice:_**File wrappers only.
133
136
134
137
To retrieve contents of a regular file wrapper use one of various convenience methods: `-data`, `-string`, `-dictionary`, `-image`.
135
138
```objective-c
@@ -147,7 +150,7 @@ let optionalData = fileWrapper.data()
147
150
let optionalString = fileWrapper.string()
148
151
```
149
152
### Updating Contents
150
-
> **_Notice:_**For file wrappers only.
153
+
> **_Notice:_**File wrappers only.
151
154
152
155
To update the contents of a regular file wrapper use `-updateContent`.
153
156
```objective-c
@@ -163,7 +166,7 @@ let fileWrapper: LSFileWrapper
163
166
fileWrapper.updateContent("Hello, World!" as NSString)
164
167
```
165
168
### Removing wrappers
166
-
> **_Notice:_**For directory wrappers only.
169
+
> **_Notice:_**Directory wrappers only.
167
170
168
171
To remove a file wrapper from existing wrapper use `-removeFileWrapper`.
169
172
```objective-c
@@ -186,7 +189,7 @@ if let wrapperToRemove = directoryWrapper.withPath("hello.txt") {
186
189
}
187
190
```
188
191
### Getting child wrappers
189
-
> **_Notice:_**For directory wrappers only.
192
+
> **_Notice:_**Directory wrappers only.
190
193
191
194
To get wrappers from a directory wrapper use `@property fileWrappers` or call `-fileWrapperWithPath`, the latter will also traverse all children based on path.
0 commit comments