In Objective-C, what does a comma do when used as a statement separator?

前端 未结 3 1237
春和景丽
春和景丽 2021-02-12 16:22

I am looking though some source code from a third party and am repeatedly seeing a syntax that is new to me. Basically they are separating statements with commas instead of semi

3条回答
  •  有刺的猬
    2021-02-12 17:20

    This is one of my favorite "features" of C, ObjC, etc…

    Understanding this operator unlocks all sorts of possibilities for jQuery-like.chain-able.commands, and a more concise (thoug-some-would-argue-less-readable) expression of MANY common idioms.. For example...

    -(id)init { 
         return self != super.init ? nil : [self setProperty:@"EPIC"], 
         NSLog(@"One line inits are: %@.", _property), self;        }
    

    LOG ➜ One line inits are: EPIC.

提交回复
热议问题