Type of security for inside

I have been experimenting with type safety in lens c for some time. I think I have some of them, but I wonder if the following is possible.

NSMutableArray <NSNumber *> *x = [NSMutableArray new];
[x addObject:@14];
[x addObject:@"s"]; // <--- Gives warning, good!

for (NSUInteger i = 0; i < x.count; i++) {
    NSString *s = [x objectAtIndex:i]; // <-- Gives warning, good!
}

NSString *d = x[0]; // <-- Gives warning, good!


//but
for (NSString *s in x) // <-- expected warning but didn't get it
    NSLog(@"%@", [s stringByAppendingString:@"s"]; // <-- no warning just run time error

So my question is: can a for in loop cause a warning when using an invalid object. I want to use for for as it quickly hides implementation details.

+4
source share
2 answers

Here is the problem.

NSArray/NSMutableArray, addObject: objectAtIndexedSubscript: ( [index]), ObjectType. ObjectType - , " ", .

NSFastEnumeration countByEnumeratingWithState:objects:count:. , objects C- id. ObjectType. id, , , NSArray.

+2

. , NSFastEnumeration, . , . , Apple LLVM

0

Source: https://habr.com/ru/post/1617714/


All Articles