开发者

Multi values parameter

开发者 https://www.devze.com 2023-03-10 08:15 出处:网络
Can anyone explain to me how to pass multiple values into a parameter or variable in objective-c as below and how to handle it inside method:

Can anyone explain to me how to pass multiple values into a parameter or variable in objective-c as below and how to handle it inside method:

view.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin 
                      | UIViewAutoresizingFlexibleT开发者_运维问答opMargin;


What you're seeing is a simple disjunction between integers, the UIView autoresizing mask parameters are just typedef'ed enum values. You can create these on your own:

typedef enum {
    IceCreamChocolateSyrup = 1 << 1,
    IceCreamCaramelSyrup = 1 << 2,
    IceCreamMapleSyrup = 1 << 3,
    // etc. up to 31 flavors
} IceCreamSyrups;

Then you define a method that accepts them as parameter:

- (void)addIceCreamSyrups:(IceCreamSyrups)syrups {
    if (syrups & IceCreamChocolateSyrup)
        [self addChocolateSyrup];

    if (syrups & IceCreamCaramelSyrup)
        [self addCaramelSyrup];

    if (syrups & IceCreamMapleSyrup)
        [self addMapleSyrup];
}

And call this method as follows:

[self addIceCreamSyrups:(IceCreamChocolateSyrup | IceCreamMapleSyrup)];
0

精彩评论

暂无评论...
验证码 换一张
取 消