Meda
Meda

Reputation: 2936

Is there a "with" statement in Objective-C?

I'm looking for something like:

with car.body.wheel 
begin
.airPressure = 3.0;
.diameter = 20;
end

I could write a macro for it I guess, but was wondering if there is anything build-in.

Upvotes: 0

Views: 227

Answers (2)

Skotch
Skotch

Reputation: 3091

The answer is no, there is no such thing in Objective C.

Just do this

XObject *x = car.body.wheel;
x.airPressure = 3.0;
x.diameter = 20;

Of course, change XObject to whatever type wheel is

Update: got rid of the id syntax

Upvotes: 3

Andrew Madsen
Andrew Madsen

Reputation: 21373

No. Rather than writing a macro for it, which is likely to make your code hard for other Objective-C programmers to read, you should just do it the normal ObjC way:

car.body.wheel.airPressure = 3.0;
car.body.wheel.diameter = 20;

Upvotes: 3

Related Questions