I have a project that used to support pre-iOS 15 versions but now only supports iOS 15+. Since the change, I received the following Xcode warning for the following line of code:
let itemProvider = NSItemProvider(item: NSData(data: data), typeIdentifier: kUTTypePlainText as String)
‘kUTTypePlainText’ was deprecated in iOS 15.0: Use UTTypePlainText instead.
Substituting UTTypePlainText in does not remedy the warning because it cannot find it in scope. The following also does not work:
let itemProvider = NSItemProvider(item: NSData(data: data), typeIdentifier: UTType.plainText)
I can’t find any clear documentation on this type. I’ve imported UniformTypeIdentifiers, CoreFoundation, CoreServices, and MobileCoreServices to no avail.
>Solution :
After importing UniformTypeIdentifiers you can use UTType.plainText to get the needed UTType. Then use its identifier property to get the String.
So your line becomes:
let itemProvider = NSItemProvider(item: NSData(data: data), typeIdentifier: UTType.plainText.identifier)