I am trying to create a protocol for JSON loading delegation, JSONLoaderDelegate. My other class, called JSONLoader, is supposed to dispatch events to its delegate (that implements the JSONLoaderDelegate protocol) like:
self?.delegate?.jsonLoaderdidEndWithError(self!, error: JSONLoaderError.LoadError)
The implementation of the JSONLoader is not that important (imho). However I seem to have problems to implement the protocol, this is the code:
@objc protocol JSONLoaderDelegate {
optional func jsonLoaderdidBeginLoading(jsonLoader: JSONLoader)
func jsonLoaderdidEndWithError(jsonLoader: JSONLoader, error: JSONLoader.JSONLoaderError)
func jsonLoaderDidEndWithSuccess(jsonLoader: JSONLoader)
}
This looks pretty straightforward to me but I am getting an error:
method cannot be marked @objc because the type of the parameter cannot be represented in Objective-C.
pointed to all three functions.
Obviously, if I remove the @objc attribute I cannot use the optional for the function. I would really like to keep jsonLoaderdidBeginLoading as optional tho. Any ideas / ways to solve this? Thank you!