下面是一个方法调用,我试图访问r对象的属性,但我不知道如何访问它们。
r
methodChannel.invokeMethod("DoSomething",arguments: link, result: { (r: Any?) -> () in debugPrint("invoked method") // TODO: How do I access r's properties? })
下面是它在调试器查看器中的外观:
如何访问r对象中的message属性?
message
irtuqstp1#
你不能访问Any的属性,因为它没有属性--它只是代表一个未指定的类型。要访问示例的属性,你需要将它强制转换为具体类型。从调试器输出的外观来看,基础类型是FlutterError,因此您可以访问它的属性,如
Any
FlutterError
if let error = r as? FlutterError { // access any properties of FlutterError } else { //handle it not being the FlutterError type you expected! }
1条答案
按热度按时间irtuqstp1#
你不能访问
Any
的属性,因为它没有属性--它只是代表一个未指定的类型。要访问示例的属性,你需要将它强制转换为具体类型。从调试器输出的外观来看,基础类型是
FlutterError
,因此您可以访问它的属性,如