Search code examples
macos-catalinaswift4.2

Cannot convert call result type 'Set<String>' to expected type 'String' error


I am working on an old Swift 3 project and I'm getting this error after updating it to Swift 4.2. It seems to work fine in Swift 3. I had to declare let NSURLPboardType = NSPasteboard.PasteboardType(kUTTypeURL as String) because NSURLPboardType does not exist in Swift 4.2 but otherwise the code is the same.

enum SparkleDrag {
    static let type = "com.razeware.StickerDrag.AppAction"
    static let action = "make sparkles"
}

let NSURLPboardType = NSPasteboard.PasteboardType(kUTTypeURL as String)
  
var nonURLTYpes: Set<String> {return [String(kUTTypeTIFF), SparkleDrag.type]}
  
var acceptableTypes: Set<String> {return [nonURLTYpes.union(NSURLPboardType)]}

The "u" in union is underlined with the error but I don't quite understand the nature of the problem. Any guidance would be much appreciated.


Solution

  • The problem is that NSURLPboardType is not a Set<String>, so the union cannot work.

    If you're trying to get something like this:

    ["com.razeware.StickerDrag.AppAction", "public.url", "public.tiff"]
    

    in aceptableTypes, you can simply forgo NSURLPboardType and do this:

    enum SparkleDrag {
        static let type = "com.razeware.StickerDrag.AppAction"
        static let action = "make sparkles"
    }
    
    // let NSURLPboardType = NSPasteboard.PasteboardType(kUTTypeURL as String)
      
    var nonURLTYpes: Set<String> {return [String(kUTTypeTIFF), SparkleDrag.type]}
      
    var acceptableTypes: Set<String> {return nonURLTYpes.union([kUTTypeURL as String])}