Swift:"Value of type 'Any' has no member 'map'" 数组返回类型 Any

Swift: "Value of type 'Any' has no member 'map'" with array returned as type Any

我正在 return 从指定它的 return 类型为 Any 的函数中获取一个数组。我指定 return type any 是因为有时这个函数不 return 一个数组,而这个函数可以 return 任何东西。这是我的代码

import Foundation

func example() -> Any {
    return ["Example"]
}

func example2() {
    example().map {[=12=]}
}

我收到这个错误

Value of type 'Any' has no member 'map'

我怎样才能摆脱这个错误并拥有一个可以 return 任何东西的函数,包括 Any[Any]

您需要将其转换为数组

func example2() {
    if let array = example() as? [Any] {
       let map = array.map {[=10=]} 
    }
}