1

When I declare a @property it is obvious that I would like to use it later. For some reasons declaring @property is not enough and I have to tell compiler to @synthetize it in every .m file. Because of this every .m file in my projects starts with @synthetize.

Why they did not do it in a C# way, where just declaration is enough and compiler do the rest?

TOP KEK
  • 2,593
  • 5
  • 36
  • 62
  • AppCode can do it. Xcode cann't by default. – beryllium Apr 01 '12 at 20:17
  • Do you mean IDE from JetBrains? – TOP KEK Apr 01 '12 at 20:19
  • yes I do. (And some characters more to achieve 15 symbols in comment :) – beryllium Apr 01 '12 at 20:23
  • 1
    In the near future it _likely_ won't be necessary to type `@synthesize` anymore due to changes in LLVM: http://www.mcubedsw.com/blog/index.php/site/comments/new_objective-c_features/ – Wolfgang Schreurs Apr 01 '12 at 20:51
  • @WolfgangSchreurs: The note there suggests that this has been removed indefinitely: «NB: This feature is no longer available and so should not be used. It may re-appear at some point but in the mean time we sadly have to write our @synthesize statements.», and [bbum indicates](http://stackoverflow.com/a/4070382/) that it was part of LLVM 2.0; since we are now on v3 and climbing, it's unclear that default `@synthesize` actually represents the future. – jscs Apr 01 '12 at 20:58

2 Answers2

4

By making @synthesize optional, you are free to implement your getter and setter methods in any way you choose.

You can find more information in Apple's Declared Properties documentation, particularly the section titled "Property Implementation Directives".

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
  • 1
    Couldn't `@synthesize` be the default, though, unless a getter and/or setter is explicitly implemented, or `@dynamic` is specified instead? – yuji Apr 01 '12 at 20:23
  • IIRC if you use `@synthesize` and still implement a getter and/or setter, the one you implement will be used instead. This can be useful for synthesizing a getter and providing a custom setter for instance. But then it doesn't help explaining why `@synthesize` has to be written manually all the time ;) – Taum Apr 01 '12 at 20:23
  • yeah, what was the reason not to choose default implementation of @synthetize which can be overridden by user? – TOP KEK Apr 01 '12 at 20:48
0

You get standard Accessors almost for free and its possible to roll your own Getters / Setter if necessary.

hburde
  • 1,441
  • 11
  • 6