Skip to content

Commit 9ef2cf9

Browse files
i2h3camilasan
authored andcommitted
feat: Introduced SwiftFormat.
Signed-off-by: Iva Horn <iva.horn@nextcloud.com>
1 parent 8403a2c commit 9ef2cf9

6 files changed

Lines changed: 33 additions & 189 deletions

File tree

.github/workflows/swiftformat.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: SwiftFormat
2+
on: pull_request
3+
4+
jobs:
5+
Lint:
6+
runs-on: macos-latest
7+
steps:
8+
- uses: actions/checkout@v4
9+
- name: SwiftFormat
10+
run: swiftformat --lint . --reporter github-actions-log
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This workflow will build a Swift project
22
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift
33

4-
name: Xcodebuild build and test
4+
name: Xcode
55

66
on:
77
push:
@@ -10,19 +10,20 @@ on:
1010
branches: [ "main" ]
1111

1212
jobs:
13-
build:
13+
test:
1414

15-
runs-on: macos-14
15+
runs-on: macos-latest
1616

1717
steps:
1818
- uses: actions/checkout@v3
1919

20-
- name: List Xcode installations
21-
run: sudo ls -1 /Applications | grep "Xcode"
22-
- name: Select Xcode 16.2
23-
run: sudo xcode-select -s /Applications/Xcode_16.2.app/Contents/Developer
24-
- name: Build and test
20+
- uses: maxim-lobanov/setup-xcode@v1
21+
with:
22+
xcode-version: latest-stable
23+
24+
- name: Run Tests
2525
run: xcodebuild clean build test -scheme NextcloudFileProviderKit -destination "platform=macOS,name=My Mac" -enableCodeCoverage YES -derivedDataPath NKFPK/.derivedData
26+
2627
- name: Gather code coverage
2728
run: |
2829
cd NKFPK/.derivedData/Build/ProfileData

.swift-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5.10

.swiftformat

Whitespace-only changes.

Package.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ let package = Package(
1717
targets: ["NextcloudFileProviderKit"]),
1818
],
1919
dependencies: [
20-
.package(
21-
url: "https://github.com/claucambra/NextcloudCapabilitiesKit.git",
22-
.upToNextMajor(from: "2.3.0")
23-
),
20+
.package(url: "https://github.com/nextcloud/NextcloudCapabilitiesKit.git", from: "2.3.0"),
2421
.package(url: "https://github.com/nextcloud/NextcloudKit", from: "7.0.0"),
22+
.package(url: "https://github.com/nicklockwood/SwiftFormat", from: "0.55.0"),
2523
.package(url: "https://github.com/realm/realm-swift.git", from: "20.0.1"),
2624
.package(url: "https://github.com/apple/swift-nio.git", from: "2.0.0")
2725
],

README.md

Lines changed: 11 additions & 177 deletions
Original file line numberDiff line numberDiff line change
@@ -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

21549
This project is licensed under the LGPLv3 License. See the [LICENSE](LICENSE) file for more details.

0 commit comments

Comments
 (0)