This is how it is defined in objective-c:
@interface AFHTTPRequestOperation : AFURLConnectionOperation
@property (readonly, nonatomic, strong) id responseObject;
How to assign sth to this property?
I would like to mock this property for later usage. So I need there my own responseObject
overriden in Swift. Any ideas how to do this? I can subclass, extend or whatever. The only thing is it must by type of AFHTTPRequestOperation
.
class MyRequestOperation: AFHTTPRequestOperation {
override var responseObject: [String: AnyObject]
}
It produces an error:
Getter for responseObject with Objective-C selector responseObject conflicts with getter for responseObject from superclass AHTTPRequestOperation with the same Objective-C selector
So, the answer is simple as @Atul Mishra said:
class MyRequestOperation: AFHTTPRequestOperation {
var myOverridenResponseObject: AnyObject?
override var responseObject: AnyObject? {
get {
return myOverridenResponseObject
}
set {
myOverridenResponseObject = newValue
}
}
}
You can present an inherited read-only property as a read-write property by providing both a getter and a setter in your subclass property override.but however you cannot provide an inherited read-write property as read-only property. for better clarification refer https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Inheritance.html#//apple_ref/doc/uid/TP40014097-CH17-XID_300
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With