Liz Liz - 2 months ago 10
iOS Question

Swift Action Extension NSString error?

I am new to Swift! So I am building an action extension in Swift and an error appears

itemProvider.loadItemForTypeIdentifier(kUTTypePropertyList as NSString, options: nil, completionHandler: { [unowned self] (result: NSSecureCoding!, error: NSError!) -> Void in


The error seems to be at the NSString. The error reads:

'NSString' is not simplicity convertible to 'String': did you mean to use 'as' to explicitly convert

I change it the NSString to

kUTTypePropertyList as String


I get another error saying:

Cannot convert value of type '(NSSecureCoding!, NSError!) -> Void to expected argument type 'NSItemProviderCompletionHandler?'

How do I solve this error? Thank you!

Answer

According to the documentation, NSItemProviderCompletionHandler is defined as (NSSecureCoding?, NSError!) -> Void, but you've used (NSSecureCoding!, NSError!) -> Void.

On result, simply change your ! to ? and it should work.