0

Xcode auto generated this swift line for a protocol - I just started the class and Xcode complete with all the protocol functions:

func `self`() -> Self {
        <#code#>
    }

EDIT: Here is the whole code:

import Foundation
import ImageCaptureCore

class myDeviceBrowserDelegate : ICDeviceBrowserDelegate {
    func deviceBrowser(_ browser: ICDeviceBrowser, didAdd device: ICDevice, moreComing: Bool) {
        <#code#>
    }

    func deviceBrowser(_ browser: ICDeviceBrowser, didRemove device: ICDevice, moreGoing: Bool) {
        <#code#>
    }

    func isEqual(_ object: Any?) -> Bool {
        <#code#>
    }

    var hash: Int = 0

    var superclass: AnyClass?

    func `self`() -> Self {
        <#code#>
    }

    func perform(_ aSelector: Selector!) -> Unmanaged<AnyObject>! {
        <#code#>
    }

    func perform(_ aSelector: Selector!, with object: Any!) -> Unmanaged<AnyObject>! {
        <#code#>
    }

    func perform(_ aSelector: Selector!, with object1: Any!, with object2: Any!) -> Unmanaged<AnyObject>! {
        <#code#>
    }

    func isProxy() -> Bool {
        <#code#>
    }

    func isKind(of aClass: AnyClass) -> Bool {
        <#code#>
    }

    func isMember(of aClass: AnyClass) -> Bool {
        <#code#>
    }

    func conforms(to aProtocol: Protocol) -> Bool {
        <#code#>
    }

    func responds(to aSelector: Selector!) -> Bool {
        <#code#>
    }

    var description: String = ""


}

but its giving an error: Method cannot be an implementation of an @objc requirement because its result type cannot be represented in Objective-C

How do you clear the error? thanks

codesurfer
  • 43
  • 8
  • 4
    Please post a [mcve] – Martin R Mar 22 '19 at 12:24
  • When you say "for a protocol," include the protocol. The mistake is almost certainly there. – Rob Napier Mar 22 '19 at 12:59
  • 1
    You have a func named `self` in your protocol? That is probably a bad idea but I haven't tested myself. – Joakim Danielson Mar 22 '19 at 13:19
  • Did you try to make a pure Swift object conform to `NSObjectProtocol`? – Rob Napier Mar 22 '19 at 13:53
  • I edited the question to show the whole code. I just started the class and Xcode filled in the rest, yet it has the error mentioned. – codesurfer Mar 23 '19 at 13:17
  • ICDeviceBrowserDelegate is an NSObject but why would Xcode generate a conforming protocol with errors? – codesurfer Mar 23 '19 at 13:32
  • Looking at [this question](https://stackoverflow.com/questions/38973881/swift-scanning-with-ikscannerdeviceview-on-osx) the implementation looks quite different. Why not remove everything and instead manually add the methods from the protocol instead of relying on Xcode. – Joakim Danielson Mar 23 '19 at 15:08
  • I have to have the methods dictated by the protocol. If I delete anything, it will error. I can leave them empty and do nothing but as far as I know they have to be declared. I tried deleting the self method and of course it error. – codesurfer Mar 23 '19 at 16:11

1 Answers1

0

I found the problem. My delegate needs to declare its superclass which is NSObject... like so:

class myDeviceBrowserDelegate : NSObject, ICDeviceBrowserDelegate {
...

Then the self function (among others) was shown as overriding the protocol definition, so I was able to now just delete those functions. Actually, only the two first functions I must declare.

I found this link that helped explain the writing of a delegate in swift: https://medium.com/@agoiabeladeyemi/protocol-in-swift-with-practical-examples-8b955268ce39

codesurfer
  • 43
  • 8