@@ -26,190 +26,24 @@ dependencies: [
2626
2727## Usage
2828
29- To use NextcloudFileProviderKit in your application, you can refer to the following example code that demonstrates how to implement various functionalities of the ` FileProviderExtension ` class.
29+ This section has been removed due to being out of dated and frequent changes to the code.
30+ As a reference, you can have a look at [ this Xcode project] ( https://github.com/nextcloud/desktop/tree/master/shell_integration/MacOSX/NextcloudIntegration ) in the Nextcloud desktop client.
31+ There are also plans to make this package more self-contained than it currently is and some code will be migrated from the other project to this one.
3032
31- ### Initialization
32-
33- ``` swift
34- import NextcloudKit
35- import NextcloudFileProviderKit
36-
37- let ncKit = NextcloudKit ()
38- ncKit.setup (
39- account : " username https://cloud.mycloud.com" ,
40- user : " username" ,
41- userId : " username" ,
42- password : " password" ,
43- urlBase : " https://cloud.mycloud.com"
44- )
45-
46- ```
47-
48- ### Fetching Item
49-
50- ``` swift
51- func item (
52- for identifier : NSFileProviderItemIdentifier,
53- request _ : NSFileProviderRequest,
54- completionHandler : @escaping (NSFileProviderItem? , Error ? ) -> Void
55- ) -> Progress {
56- if let item = Item.storedItem (identifier : identifier, remoteInterface : ncKit) {
57- completionHandler (item, nil )
58- } else {
59- completionHandler (
60- nil , NSError.fileProviderErrorForNonExistentItem (withIdentifier : identifier)
61- )
62- }
63- return Progress ()
64- }
65- ```
66-
67- ### Fetching Contents
68-
69- ``` swift
70- func fetchContents (
71- for itemIdentifier : NSFileProviderItemIdentifier,
72- version requestedVersion : NSFileProviderItemVersion? ,
73- request : NSFileProviderRequest,
74- completionHandler : @escaping (URL? , NSFileProviderItem? , Error ? ) -> Void
75- ) -> Progress {
76- guard requestedVersion == nil else {
77- completionHandler (
78- nil ,
79- nil ,
80- NSError (domain : NSCocoaErrorDomain, code : NSFeatureUnsupportedError)
81- )
82- return Progress ()
83- }
84-
85- guard let item = Item.storedItem (identifier : itemIdentifier, remoteInterface : ncKit) else {
86- completionHandler (
87- nil , nil , NSError.fileProviderErrorForNonExistentItem (withIdentifier : itemIdentifier)
88- )
89- return Progress ()
90- }
91-
92- let progress = Progress ()
93- Task {
94- let (localUrl, updatedItem, error) = await item.fetchContents (domain : self .domain , progress : progress)
95- completionHandler (localUrl, updatedItem, error)
96- }
97- return progress
98- }
99- ```
100-
101- ### Creating Item
102-
103- ``` swift
104- func createItem (
105- basedOn itemTemplate : NSFileProviderItem,
106- fields : NSFileProviderItemFields,
107- contents url : URL? ,
108- options : NSFileProviderCreateItemOptions = [],
109- request : NSFileProviderRequest,
110- completionHandler : @escaping (NSFileProviderItem? , NSFileProviderItemFields, Bool , Error ? ) -> Void
111- ) -> Progress {
112- let progress = Progress ()
113- Task {
114- let (item, error) = await Item.create (
115- basedOn : itemTemplate,
116- fields : fields,
117- contents : url,
118- request : request,
119- domain : self .domain ,
120- remoteInterface : ncKit,
121- progress : progress
122- )
123- completionHandler (item ?? itemTemplate, NSFileProviderItemFields (), false , error)
124- }
125- return progress
126- }
127- ```
128-
129- ### Modifying Item
130-
131- ``` swift
132- func modifyItem (
133- _ item : NSFileProviderItem,
134- baseVersion : NSFileProviderItemVersion,
135- changedFields : NSFileProviderItemFields,
136- contents newContents : URL? ,
137- options : NSFileProviderModifyItemOptions = [],
138- request : NSFileProviderRequest,
139- completionHandler : @escaping (NSFileProviderItem? , NSFileProviderItemFields, Bool , Error ? ) -> Void
140- ) -> Progress {
141- guard let existingItem = Item.storedItem (identifier : item.itemIdentifier , remoteInterface : ncKit) else {
142- completionHandler (
143- item,
144- [],
145- false ,
146- NSError.fileProviderErrorForNonExistentItem (withIdentifier : item.itemIdentifier )
147- )
148- return Progress ()
149- }
150-
151- let progress = Progress ()
152- Task {
153- let (modifiedItem, error) = await existingItem.modify (
154- itemTarget : item,
155- baseVersion : baseVersion,
156- changedFields : changedFields,
157- contents : newContents,
158- options : options,
159- request : request,
160- domain : domain,
161- progress : progress
162- )
163- completionHandler (modifiedItem ?? item, [], false , error)
164- }
165- return progress
166- }
167- ```
33+ ## Contributing
16834
169- ### Deleting Item
35+ Contributions are welcome! Please feel free to submit a pull request or open an issue if you encounter any problems or have suggestions for improvements.
17036
171- ``` swift
172- func deleteItem (
173- identifier : NSFileProviderItemIdentifier,
174- baseVersion _ : NSFileProviderItemVersion,
175- options _ : NSFileProviderDeleteItemOptions = [],
176- request _ : NSFileProviderRequest,
177- completionHandler : @escaping (Error ? ) -> Void
178- ) -> Progress {
179- guard let item = Item.storedItem (identifier : identifier, remoteInterface : ncKit) else {
180- completionHandler (NSError.fileProviderErrorForNonExistentItem (withIdentifier : identifier))
181- return Progress ()
182- }
183-
184- let progress = Progress (totalUnitCount : 1 )
185- Task {
186- let error = await item.delete ()
187- progress.completedUnitCount = 1
188- completionHandler (await item.delete ())
189- }
190- return progress
191- }
192- ```
37+ ### Code Style
19338
194- ### Enumerator
39+ [ SwiftFormat] ( https://github.com/nicklockwood/SwiftFormat ) was introduced into this project.
40+ Before submitting a pull request, please ensure that your code changes comply with the currently configured code style.
41+ You can run the following command in the root of the package repository clone:
19542
196- ``` swift
197- func enumerator (
198- for containerItemIdentifier : NSFileProviderItemIdentifier,
199- request _ : NSFileProviderRequest
200- ) throws -> NSFileProviderEnumerator {
201- return Enumerator (
202- enumeratedItemIdentifier : containerItemIdentifier,
203- remoteInterface : ncKit,
204- domain : domain
205- )
206- }
43+ ``` bash
44+ swift package plugin --allow-writing-to-package-directory swiftformat --verbose --cache ignore --swift-version 5.9
20745```
20846
209- ## Contributing
210-
211- Contributions are welcome! Please feel free to submit a pull request or open an issue if you encounter any problems or have suggestions for improvements.
212-
21347## License
21448
21549This project is licensed under the LGPLv3 License. See the [ LICENSE] ( LICENSE ) file for more details.
0 commit comments