Argument type 'customClass.Type' does not conform to expected type 'NSItemProviderWriting'

前端 未结 1 807
小蘑菇
小蘑菇 2021-01-21 02:09

iOS 11.x Swift 4

Trying to implement a custom class for using the new drop and drag protocol and need some super-coder help. I created this class.

import         


        
相关标签:
1条回答
  • 2021-01-21 03:05

    The error message is correct and your line:

    let itemProvider = NSItemProvider(object: customClass)
    

    is incorrect for the reason stated. The object parameter is expecting an instance of some class that conforms to the NSItemProviderWriting protocol. But you are passing in an actual class, not an instance of the class.

    Replace customClass with an actual instance of your customClass. If this method is inside your customClass, then pass self.

    let itemProvider = NSItemProvider(object: self)
    

    BTW - this would be less confusing if your followed standard naming conventions. Class and struct names should begin with uppercase letters. Variable and method names start with lowercase letters. So your customClass should be named CustomClass.

    0 讨论(0)
提交回复
热议问题