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
* 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
+
* Remove `Content-Type`, `Content-Length` headers and body from websocket requests
9
+
10
+
## 10.1.1
11
+
12
+
* Adds warnings to bulk operation methods
13
+
* Fix select Queries by updating internal attributes like id, createdAt, updatedAt etc. to be optional in Document model.
14
+
* Fix querying datetime values by properly encoding URLs
15
+
16
+
## 10.1.0
17
+
18
+
* Add `devKeys` support to `Client` service
19
+
* Add `upsertDocument` support to `Databases` service
20
+
3
21
## 10.0.0
4
22
5
-
* Add `<REGION>` to doc examples due to the new multi region endpoints
23
+
* Add `<REGION>` to doc examples due to the new multi region endpoints
6
24
* Add `token` param to `getFilePreview` and `getFileView` for File tokens usage
7
25
* Remove `search` param from `listExecutions` method
8
-
* Remove `Gif` from ImageFormat enum
26
+
* Remove `Gif` from ImageFormat enum
27
+
28
+
## 9.0.1
29
+
30
+
* Fix requests failing by removing `Content-Type` header from `GET` and `HEAD` requests
31
+
32
+
## 9.0.0
33
+
34
+
* Remove redundant titles from method descriptions.
35
+
* Add `codable` models
36
+
* Ensure response attribute in `AppwriteException` is always string
The Appwrite Apple 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.
169
+
170
+
```swift
171
+
structBook: Codable {
172
+
let name: String
173
+
let author: String
174
+
let releaseYear: String?
175
+
let category: String?
176
+
let genre: [String]?
177
+
let isCheckedOut: Bool
178
+
}
179
+
180
+
let databases =Databases(client)
181
+
182
+
do {
183
+
let documents =tryawait databases.listDocuments(
184
+
databaseId: "your-database-id",
185
+
collectionId: "your-collection-id",
186
+
nestedType: Book.self// Pass in your custom model type
187
+
)
188
+
189
+
for book in documents.documents {
190
+
print("Book: \(book.name) by \(book.author)") // Now you have full type safety
191
+
}
192
+
} catch {
193
+
print(error.localizedDescription)
194
+
}
195
+
```
196
+
197
+
**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).
198
+
199
+
### Working with Model Methods
200
+
201
+
All Appwrite models come with built-in methods for data conversion and manipulation:
202
+
203
+
**`toMap()`** - Converts a model instance to a dictionary format, useful for debugging or manual data manipulation:
204
+
```swift
205
+
let user =tryawait account.get()
206
+
let userMap = user.toMap()
207
+
print(userMap) // Prints all user properties as a dictionary
208
+
```
209
+
210
+
**`from(map:)`** - Creates a model instance from a dictionary, useful when working with raw data:
211
+
```swift
212
+
let userData: [String: Any] = ["$id":"123", "name":"John", "email":"[email protected]"]
213
+
let user = User.from(map: userData)
214
+
```
215
+
216
+
**`encode(to:)`** - Encodes the model to JSON format (part of Swift's Codable protocol), useful for serialization:
217
+
```swift
218
+
let user =tryawait account.get()
219
+
let jsonData =tryJSONEncoder().encode(user)
220
+
let jsonString =String(data: jsonData, encoding: .utf8)
221
+
```
222
+
166
223
### Error Handling
167
224
168
225
When an error occurs, the Appwrite Apple 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.
0 commit comments