Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
As generated
  • Loading branch information
stuartmorgan-g committed Jan 19, 2024
commit 89fa695cd4f191285cc48b8e73879fe2e378e2fc
37 changes: 19 additions & 18 deletions packages/pigeon/example/app/ios/Runner/Messages.g.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
// See also: https://pub.dev/packages/pigeon

import Foundation

#if os(iOS)
import Flutter
import Flutter
#elseif os(macOS)
import FlutterMacOS
import FlutterMacOS
#else
#error("Unsupported platform.")
#error("Unsupported platform.")
#endif

private func wrapResult(_ result: Any?) -> [Any?] {
Expand All @@ -22,13 +23,13 @@ private func wrapError(_ error: Any) -> [Any?] {
return [
flutterError.code,
flutterError.message,
flutterError.details
flutterError.details,
]
}
return [
"\(error)",
"\(type(of: error))",
"Stacktrace: \(Thread.callStackSymbols)"
"Stacktrace: \(Thread.callStackSymbols)",
]
}

Expand Down Expand Up @@ -83,10 +84,10 @@ struct MessageData {
private class ExampleHostApiCodecReader: FlutterStandardReader {
override func readValue(ofType type: UInt8) -> Any? {
switch type {
case 128:
return MessageData.fromList(self.readValue() as! [Any?])
default:
return super.readValue(ofType: type)
case 128:
return MessageData.fromList(self.readValue() as! [Any?])
default:
return super.readValue(ofType: type)
}
}
}
Expand Down Expand Up @@ -165,10 +166,10 @@ class ExampleHostApiSetup {
let messageArg = args[0] as! MessageData
api.sendMessage(message: messageArg) { result in
switch result {
case .success(let res):
reply(wrapResult(res))
case .failure(let error):
reply(wrapError(error))
case .success(let res):
reply(wrapResult(res))
case .failure(let error):
reply(wrapError(error))
}
}
}
Expand All @@ -183,23 +184,23 @@ protocol MessageFlutterApiProtocol {
}
class MessageFlutterApi: MessageFlutterApiProtocol {
private let binaryMessenger: FlutterBinaryMessenger
init(binaryMessenger: FlutterBinaryMessenger){
init(binaryMessenger: FlutterBinaryMessenger) {
self.binaryMessenger = binaryMessenger
}
func flutterMethod(aString aStringArg: String?, completion: @escaping (Result<String, FlutterError>) -> Void) {
let channelName: String = "dev.flutter.pigeon.pigeon_example_package.MessageFlutterApi.flutterMethod"
let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger)
channel.sendMessage([aStringArg] as [Any?]) { response in
guard let listResponse = response as? [Any?] else {
completion(.failure(createConnectionError(withChannelName:channelName)))
completion(.failure(createConnectionError(withChannelName: channelName)))
return
}
if (listResponse.count > 1) {
if listResponse.count > 1 {
let code: String = listResponse[0] as! String
let message: String? = nilOrValue(listResponse[1])
let details: String? = nilOrValue(listResponse[2])
completion(.failure(FlutterError(code: code, message: message, details: details)));
} else if (listResponse[0] == nil) {
completion(.failure(FlutterError(code: code, message: message, details: details)))
} else if listResponse[0] == nil {
completion(.failure(FlutterError(code: "null-error", message: "Flutter api returned null value for non-null return value.", details: "")))
} else {
let result = listResponse[0] as! String
Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/lib/swift_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ class SwiftGenerator extends StructuredGenerator<SwiftOptions> {
indent.writeScoped(
'guard let listResponse = response as? [Any?] else {', '}', () {
indent.writeln(
'completion(.failure(createConnectionError(withChannelName:channelName)))');
'completion(.failure(createConnectionError(withChannelName: channelName)))');
indent.writeln('return');
});
indent.writeScoped('if listResponse.count > 1 {', '} ', () {
Expand Down
Loading