如何在App和Bundle中使用相同的类?

时间:2019-10-30 13:49:04

标签: ios swift

在我的应用中,我正在将一个对象从我的应用传递到我的捆绑包中。问题在于Swift认为它们是另一种类型。因此,当我进行检查时,它将失败,并说MyApp.RestaurantMyBundle.Restaurant是不同的。

func exportRestaurant(_ restaurant: Restaurant) {
    if let restaurant: Restaurant = restaurant as? Restaurant {
        // This will never be executed.
    }
    let restaurant: Restaurant = restaurant as! Restaurant
    // This will crash the app. Could not cast value of type 'MyApp.Restaurant' (0x100ba6460) to 'MyAppSupportingBundle.Restaurant' (0x104eaaec0).
}

因此,我无法将其转换为类型。有什么办法可以克服这个问题?

0 个答案:

没有答案