How to use generics on obj-c?

With the new xcode7, Apple introduced generics and nullable for Objective-C ( Developer's Guide )

But he seems to be very different from what we have on the fast.

admissibility empty:

- (nonnull NSString *)something { return nil; } 

This should trigger a warning! And you can even assign the return value of this method to a nonnull variable, for example:

 //@property (copy, nonnull) NSString *name obj.name = [obj something]; 

Generics: In this example:

 @property (nonatomic, strong, nonnull) NSMutableArray <UIView *> *someViews; 

a warning appears when something other than a UIView is added to the array

 [self.someViews addObject:@"foobar"]; //<- this raises an error 

but not in this case:

 self.someViews = [@[@"foobar"] mutableCopy]; 

and in this case:

 NSString *str = [self.someViews firstObject]; 

So the question is am I using generics and invalid in the wrong order or are they far from the Swift implementation?

+5
source share
1 answer
 self.someViews = [@[@"foobar"] mutableCopy]; 

mutableCopy inherits from NSObject , where a return id declared. It is not specifically declared by NSArray , and NSArray does not determine the return type.

 NSString *str = [self.someViews firstObject]; 

This gives a warning to me.

+1
source

All Articles