Pure Swift Protocol 'weak var delegate' error

Pure Swift Protocol 'weak var delegate' error

Just like anyone else you have encounter this error too. Writing a pure swift protocol and declaring the weak delegate you must have encountered error mentioned below. \[swift\]...

Alok Choudhary
Austin, TX
1 min read

Just like anyone else you have encounter this error too. Writing a pure swift protocol and declaring the weak delegate you must have encountered error mentioned below. [swift] weak var delegate: TestProtocol? [/swift]

You get this error swift protocol error screenshot

There are two way to fix it. First which is highly unlikely as you would be looking if you wanted to add impurity aka objc in your code. [swift]@objc protocol TestProtocol { var someVar: Int { get set } func concat(name: String, age: Int) -> String }[/swift]

Yes adding objc directive to you protocol and you are good to go.

Second and most likely accepted method. You need to declare the type of the protocol as class. [swift] protocol TestProtocol: class { var someVar: Int { get set } func concat(name: String, age: Int) -> String } [/swift]

Very easy, isn’t it. Happy Swifting

Link copied to clipboard!

Made with ❤️ in Austin.

Copyright © 2026