What does this Objective-C dictionary code do?

前端 未结 2 890
深忆病人
深忆病人 2021-01-28 09:21

.h

@property (nonatomic, strong) NSMutableDictionary * products;  //not synthesized in .m

.m

- (void)productsRequest:(SKProduct         


        
2条回答
  •  终归单人心
    2021-01-28 10:23

    You are having trouble understanding this line:

    IAPProduct * product = _products[skProduct.productIdentifier];
    

    Lets break it down:

    NSString *key = skProduct.productIdentifier;
    IAPProduct * product = _products[key];
    

    The 2nd line is modern syntax for:

    IAProduct * product = [_products objectForKey:key];
    

    This is the normal way to lookup a value in a dictionary for a given key.

提交回复
热议问题