Liz
Liz

Reputation: 39

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!

Upvotes: 2

Views: 437

Answers (2)

z33
z33

Reputation: 1263

If you are using swift 3 syntax. it changes to :

typealias CompletionHandler = (NSSecureCoding?, Error!) -> Void

NSError -> Error

Upvotes: 0

jtbandes
jtbandes

Reputation: 118751

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.

Upvotes: 4

Related Questions