blueberryfields
blueberryfields

Reputation: 50468

iOS programming style - where does one normally expect @synthesize statements?

I've seen all kinds of variations in style for the placement of @synthesize statements. I'm wondering - is there a majority consensus for this, or, failing that, a statement from a centralized style guide (ie, apple's guide) about where to place them?

Please provide references.

Upvotes: 0

Views: 153

Answers (4)

Jeffery Thomas
Jeffery Thomas

Reputation: 42598

In Apple's examples, they place the @synthesize statements at the top of the implementation. This seems to be the way lots of people do it. I think mostly because that's how Apple does it.

I prefer having them at the bottom of the implementation. I try to order my code in such a way that the most significant code is near the top. Frankly, properties should not be all that interesting. If you have anything that's not boilerplate in your properties, then you're most likely doing it wrong.

My order is usually public methods, view lifecycle, delegate callbacks, private methods, memory management, then synthesized properties (with accessors).

Upvotes: 1

cnu
cnu

Reputation: 815

Usually just below @implementation ClassName line

So that you can see them easily and add new ones easily

Upvotes: 1

Martin
Martin

Reputation: 12215

Yes, of course it's in the @implementation... But I don't think it is the question.

I wondered same questions, as

  • where exactly place @synthesize?
  • write @synthesize for each property to load, or chain every properties in one line?

There is absolutely no diffenrence, and I'm not sure if there is kind of convention about, but here is mine ;) :

  • one line free between @implementation and @synthesize
  • properties grouped by meaning (for example, one line of UI, on line of data structures, etc...)

    @implementation MyClass
    
    @synthesize label1, label2, button;
    @synthesize array, dictionay;
    

Upvotes: 1

Snowcrash
Snowcrash

Reputation: 86307

You can use the @synthesize and @dynamic directives in @implementation blocks.

https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocProperties.html

Upvotes: 1

Related Questions