Son Nguyen
Son Nguyen

Reputation: 3481

Multi values parameter

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 
                      | UIViewAutoresizingFlexibleTopMargin;

Upvotes: 1

Views: 119

Answers (1)

Eimantas
Eimantas

Reputation: 49354

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)];

Upvotes: 2

Related Questions