NSURL getResourceValue in swift

前端 未结 5 865
梦如初夏
梦如初夏 2021-02-13 11:54

Having trouble figuring out how to make the following call in swift:

var anyError: NSError? = nil
var rsrc: NSNumber? = nil
var success = url.getResourceValue(&a         


        
5条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-13 12:07

    If the getResourceValue(:forKey:) result is ultimately a logical value, you can cast the returned pointer value directly to a Bool value:

    let boolResult = rsrc as! Bool
    

    or simply test it as a Bool value without assigning it:

    if rsrc as! Bool {
        // true code
    } else {
        // false code
    }
    

    or do both:

    if let rsrc as! Bool {
        // true
    } else {
        // false
    }
    

提交回复
热议问题