ios - How to properly use generics on obj-c? -
with new xcode7 apple introduced generics , nullability objective-c ( developer guide )
but seems different have on swift.
nullability:
- (nonnull nsstring *)something { return nil; }
this should raise warning! , can assign return value of method nonnull
variable like:
//@property (copy, nonnull) nsstring *name obj.name = [obj something];
generics: looking example:
@property (nonatomic, strong, nonnull) nsmutablearray <uiview *> *someviews;
a warning raised when different uiview inserted on array
[self.someviews addobject:@"foobar"]; //<- raises error
but not in case:
self.someviews = [@[@"foobar"] mutablecopy];
nor in case:
nsstring *str = [self.someviews firstobject];
so question is, i'm using generics , nullability in wrong way or far away swift implementation?
self.someviews = [@[@"foobar"] mutablecopy];
mutablecopy
inherited nsobject
, declared return id
. not declared nsarray
, nsarray
des not decide return type.
nsstring *str = [self.someviews firstobject];
this does give warning me.
Comments
Post a Comment