Skip to content

Commit 6de86ee

Browse files
authored
Merge pull request #83 from appwrite/dev
Add inc/dec
2 parents 52a3a6f + d9de933 commit 6de86ee

File tree

19 files changed

+882
-498
lines changed

19 files changed

+882
-498
lines changed

CHANGELOG.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,36 @@
11
# Change Log
22

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+
* 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+
321
## 10.0.0
422

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
624
* Add `token` param to `getFilePreview` and `getFileView` for File tokens usage
725
* 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

README.md

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Add the package to your `Package.swift` dependencies:
3131

3232
```swift
3333
dependencies: [
34-
.package(url: "[email protected]:appwrite/sdk-for-apple.git", from: "10.1.1"),
34+
.package(url: "[email protected]:appwrite/sdk-for-apple.git", from: "10.2.0"),
3535
],
3636
```
3737

@@ -163,6 +163,63 @@ func main() {
163163
}
164164
```
165165

166+
### Type Safety with Models
167+
168+
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+
struct Book: 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 = try await 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 = try await 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 = try await account.get()
219+
let jsonData = try JSONEncoder().encode(user)
220+
let jsonString = String(data: jsonData, encoding: .utf8)
221+
```
222+
166223
### Error Handling
167224

168225
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.

Sources/Appwrite/Client.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ open class Client {
2323
"x-sdk-name": "Apple",
2424
"x-sdk-platform": "client",
2525
"x-sdk-language": "apple",
26-
"x-sdk-version": "10.1.1",
26+
"x-sdk-version": "10.2.0",
2727
"x-appwrite-response-format": "1.7.0"
2828
]
2929

Sources/Appwrite/OAuth/WebAuthComponent.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class WebAuthComponent {
4444
url: url,
4545
callbackURLScheme: callbackScheme
4646
) { callbackURL, error in
47-
if let error = error {
47+
if error != nil {
4848
cleanUp()
4949
} else if let callbackURL = callbackURL {
5050
// handle cookies here itself!
@@ -161,7 +161,7 @@ class PresentationContextProvider: NSObject, ASWebAuthenticationPresentationCont
161161
static let shared = PresentationContextProvider()
162162

163163
func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
164-
if let mainWindow = OSApplication.shared.windows.first { $0.isKeyWindow } {
164+
if let mainWindow = OSApplication.shared.windows.first(where: { $0.isKeyWindow }) {
165165
return mainWindow
166166
}
167167

0 commit comments

Comments
 (0)