In Swift, we can create a generic property like:
class MyClass<T: MyOtherType where T: MyProtocol> {
var property: T
}
How is it possible in Objective-C?
Assuming:
@interface MyOtherType : NSObject
// Some code
@end
@protocol MyProtocol <NSObject>
// Some code
@end
You can do this:
@interface MyClass : NSObject
@property MyOtherType <MyProtocol> * property;
@end
Syntax is Class <Protocol>
.
It would be actually something like Class & Protocol
type in Swift 4+
.
Here is answer.
@interface myParentView< T: parentModel*> :UIView
@property T myObject; // myObject is object of parentModel
@end
In all subclass:
@interface myChildViewOne :myParentView<childModel>
// Now myObject is object of childModel
@end
Obj C has complicated syntax, But we can achieve generic property like above.
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