To conditionally bind a value that is not an optional type, you can use the optional casting operator as? to check if the value can be cast to a specific type. Here's an example using KFCrossPlatformImage (which I assume is a custom type):

if let image = someObject as? KFCrossPlatformImage {
    // The value of someObject is of type KFCrossPlatformImage
    // You can use the image variable here
} else {
    // The value of someObject is not of type KFCrossPlatformImage
    // Handle the else case here
}

This way, you can conditionally bind the value of someObject to the image constant only if it can be cast to KFCrossPlatformImage. If the casting fails, the else block will be executed

Initializer for conditional binding must have Optional type not KFCrossPlatformImage aka UIImage

原文地址: https://www.cveoy.top/t/topic/iQxU 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录