On Sep 29, 2016, at 04:18 , Rick Mann <[email protected]> wrote:
> 
> var vals = URLResourceValues()
> vals.isExcludedFromBackup = true
> try destURL.setResourceValues(vals)
> 
> But I get "Cannot convert value of type 'URLResourceValues' to expected 
> argument type '[URLResourceKey : AnyObject]'" on the "vals" argument. The 
> problem is that the docs say it's supposed to take [URLResourceKey : Any].
> 
> The Swift interface file generated by Xcode looks like this:
> 
>    public mutating func setResourceValues(_ values: URLResourceValues) throws
> 
> But that's clearly not what the compiler sees.

What is the type of ‘destURL’? URL or NSURL? It sounds like it’s NSURL.

The function signature in class NSURL is:

>       func setResourceValues([URLResourceKey : Any])


whereas the function signature in class URL is:

>       func setResourceValues(_ values: URLResourceValues)


So, you either need to change destURL to be a URL, or use the NSURL API that 
takes a dictionary. Note that URL is not just a cosmetic renaming of NSURL in 
Swift 3, but a whole new type that wraps a NSURL object. Both types are 
accessible, though you’re going to have the best Swift 3 experience if you 
switch to URL — and its altered API and semantics.

Regarding Any vs. AnyObject as the dictionary value, the error message I get 
(in Xcode 8.1 beta, with the above code) is:

>       Cannot convert value of type 'URLResourceValues' to expected argument 
> type '[URLResourceKey : Any]’

So, you’re either not compiling against the 10.12 SDK (which I think should be 
impossible), or you’re compiling as Swift 2.3, or Xcode at least thinks you are.

_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to