Can I do something like this?
@implementation NSObject (Tryable)
- (id)tryWithKey:(id)key {
if (!self) return [NSNull null];
if (![self isKindOfClass:NSDictionary.class]) return [NSNull null];
if (![(NSDictionary *)self objectForKey:key]
|| [(NSDictionary *)self objectForKey:key] == [NSNull null]) {
return [NSNull null];
}
return ((NSDictionary *)self)[key];
}
@end
Thus, when I handling NSDictionary, I can just ...
id whatIWant = [[[dict tryWithKey:@"aaa"] tryWithKey:@"bbb"] tryWithKey:@"ccc"];