Skip to content

Commit 8dfd3d4

Browse files
authored
Merge pull request #37 from appwrite/dev
Add inc/dec
2 parents e6ded53 + 0a0ee5d commit 8dfd3d4

35 files changed

+2471
-1836
lines changed

CHANGELOG.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,45 @@
1-
# Change Log
1+
# Change Log
2+
3+
## 10.2.0
4+
5+
* Update sdk to use swift-native doc comments instead of jsdoc styled comments as per [Swift Documentation Comments](https://github.com/swiftlang/swift/blob/main/docs/DocumentationComments.md)
6+
* Add `incrementDocumentAttribute` and `decrementDocumentAttribute` support to `Databases` service
7+
* Add `gif` support to `ImageFormat` enum
8+
* Add `sequence` support to `Document` model
9+
* Add `dart38` and `flutter332` support to runtime models
10+
11+
## 10.1.0
12+
13+
* Adds `upsertDocument` method
14+
* Adds warnings to bulk operation methods
15+
* Adds the new `encrypt` attribute
16+
* Adds runtimes: `flutter332` and `dart38`
17+
* Fix `select` Queries by updating internal attributes like `id`, `createdAt`, `updatedAt` etc. to be optional in `Document` model.
18+
* Fix `listCollection` errors by updating `attributes` typing
19+
* Fix querying datetime values by properly encoding URLs
20+
21+
## 10.0.0
22+
23+
* Add `<REGION>` to doc examples due to the new multi region endpoints
24+
* Add doc examples and methods for bulk api transactions: `createDocuments`, `deleteDocuments` etc.
25+
* Add doc examples, class and methods for new `Sites` service
26+
* Add doc examples, class and methods for new `Tokens` service
27+
* Add enums for `BuildRuntime `, `Adapter`, `Framework`, `DeploymentDownloadType` and `VCSDeploymentType`
28+
* Update enum for `runtimes` with Pythonml312, Dart219, Flutter327 and Flutter329
29+
* Add `token` param to `getFilePreview` and `getFileView` for File tokens usage
30+
* Add `queries` and `search` params to `listMemberships` method
31+
* Remove `search` param from `listExecutions` method
32+
33+
## 9.0.0
34+
35+
* Fix requests failing by removing `Content-Type` header from `GET` and `HEAD` requests
36+
37+
## 8.0.0
38+
39+
* Remove redundant titles from method descriptions.
40+
* Add `codable` models
41+
* Ensure response attribute in `AppwriteException` is always string
42+
43+
## 7.0.0
44+
45+
* Fix pong response & chunked upload

README.md

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Appwrite is an open-source backend as a service server that abstract and simplif
2121

2222
The Appwrite Swift SDK is available via Swift Package Manager. In order to use the Appwrite Swift SDK from Xcode, select File > **Add Packages**
2323

24-
In the dialog that appears, enter the Appwrite Swift SDK [package URL](git@github.com:appwrite/sdk-for-swift.git) in the search field. Once found, select `sdk-for-apple`.
24+
In the dialog that appears, enter the Appwrite Swift SDK [package URL](git@github.com:appwrite/sdk-for-swift.git) in the search field. Once found, select `sdk-for-swift`.
2525

2626
On the right, select your version rules and ensure your desired target is selected in the **Add to Project** field.
2727

@@ -33,7 +33,7 @@ Add the package to your `Package.swift` dependencies:
3333

3434
```swift
3535
dependencies: [
36-
.package(url: "git@github.com:appwrite/sdk-for-swift.git", from: "10.1.0"),
36+
.package(url: "git@github.com:appwrite/sdk-for-swift.git", from: "10.2.0"),
3737
],
3838
```
3939

@@ -118,6 +118,63 @@ func main() {
118118
}
119119
```
120120

121+
### Type Safety with Models
122+
123+
The Appwrite Swift SDK provides type safety when working with database documents through generic methods. Methods like `listDocuments`, `getDocument`, and others accept a `nestedType` parameter that allows you to specify your custom model type for full type safety.
124+
125+
```swift
126+
struct Book: Codable {
127+
let name: String
128+
let author: String
129+
let releaseYear: String?
130+
let category: String?
131+
let genre: [String]?
132+
let isCheckedOut: Bool
133+
}
134+
135+
let databases = Databases(client)
136+
137+
do {
138+
let documents = try await databases.listDocuments(
139+
databaseId: "your-database-id",
140+
collectionId: "your-collection-id",
141+
nestedType: Book.self // Pass in your custom model type
142+
)
143+
144+
for book in documents.documents {
145+
print("Book: \(book.name) by \(book.author)") // Now you have full type safety
146+
}
147+
} catch {
148+
print(error.localizedDescription)
149+
}
150+
```
151+
152+
**Tip**: You can use the `appwrite types` command to automatically generate model definitions based on your Appwrite database schema. Learn more about [type generation](https://appwrite.io/docs/products/databases/type-generation).
153+
154+
### Working with Model Methods
155+
156+
All Appwrite models come with built-in methods for data conversion and manipulation:
157+
158+
**`toMap()`** - Converts a model instance to a dictionary format, useful for debugging or manual data manipulation:
159+
```swift
160+
let user = try await account.get()
161+
let userMap = user.toMap()
162+
print(userMap) // Prints all user properties as a dictionary
163+
```
164+
165+
**`from(map:)`** - Creates a model instance from a dictionary, useful when working with raw data:
166+
```swift
167+
let userData: [String: Any] = ["$id": "123", "name": "John", "email": "john@example.com"]
168+
let user = User.from(map: userData)
169+
```
170+
171+
**`encode(to:)`** - Encodes the model to JSON format (part of Swift's Codable protocol), useful for serialization:
172+
```swift
173+
let user = try await account.get()
174+
let jsonData = try JSONEncoder().encode(user)
175+
let jsonString = String(data: jsonData, encoding: .utf8)
176+
```
177+
121178
### Error Handling
122179

123180
When an error occurs, the Appwrite Swift SDK throws an `AppwriteError` object with `message` and `code` properties. You can handle any errors in a catch block and present the `message` or `localizedDescription` to the user or handle it yourself based on the provided error information. Below is an example.

Sources/Appwrite/Client.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ open class Client {
2121
"x-sdk-name": "Swift",
2222
"x-sdk-platform": "server",
2323
"x-sdk-language": "swift",
24-
"x-sdk-version": "10.1.0",
24+
"x-sdk-version": "10.2.0",
2525
"x-appwrite-response-format": "1.7.0"
2626
]
2727

0 commit comments

Comments
 (0)