Swift Error: cannot convert of type '()' to specified type 'Bool'

前端 未结 2 1931
旧时难觅i
旧时难觅i 2021-01-23 15:24

I am New for Swift and I Have Implement File Manager Concept in my Project but it shows the issue and I don\'t for how to solve this please any body help me for fix the issue.

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-23 16:07

    The benefit of the new error handling in Swift 2 is the omission of the quasi-redundant return values Bool / NSError. Therefore setResourceValue does not return a Bool anymore which is the reason of the error message.

    As the function is marked as throws I recommend this syntax which just passes the result of setResourceValue

    class func addSkipBackupAttributeToItemAtPath(filePathString: String) throws
    {
        let url = NSURL.fileURLWithPath(filePathString)
        assert(NSFileManager.defaultManager().fileExistsAtPath(URL.path!))
    
        try url.setResourceValue(true, forKey: NSURLIsExcludedFromBackupKey)
    }
    

    Handle the error in the method which calls addSkipBackupAttributeToItemAtPath

提交回复
热议问题