Skip to content

Commit 53f4716

Browse files
authored
docs: Add note about CDVPluginResult Swift nullability (#1577)
Closes #1574.
1 parent dfd32d5 commit 53f4716

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

CordovaLib/CordovaLib.docc/upgrading-8.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,26 @@ import Foundation
167167
import UIKit
168168
```
169169

170+
### `CDVPluginResult` Swift optionality
171+
172+
The `CDVPluginResult` constructors have been annotated as returning a non-null object, which means the constructor in Swift no longer returns an optional value that needs to be unwrapped. However, this means that attempts to unwrap the value will now be errors.
173+
174+
In most cases, you shouldn't need to worry about the optionality of the result before passing it to `commandDelegate.send` but if you are setting other options then you might need to explicitly store as an optional for backwards compatibility:
175+
176+
```swift
177+
// Old code (Swift)
178+
let result = CDVPluginResult(status: .ok, messageAs: "some value")!
179+
result.setKeepCallbackAs(true)
180+
self.commandDelegate.send(result, callbackId: callback)
181+
```
182+
183+
```swift
184+
// New code (Swift)
185+
let result: CDVPluginResult? = CDVPluginResult(status: .ok, messageAs: "some value")
186+
result?.setKeepCallbackAs(true)
187+
self.commandDelegate.send(result, callbackId: callback)
188+
```
189+
170190
## Other Major Changes
171191
### Deprecating AppDelegate category extensions
172192

0 commit comments

Comments
 (0)