ios - How do I disable property auto-synthesis of properties in Xcode 5? -


I automatically generate NSUserDefaults accessors based on the @ dynamic properties based on the properties you declare For a library has written a 'preferences' category (see) you like this one. M writes property in file:

  @property (nonatomic, assign) BOOLSeenIntro;  

And then add it to the .h file:

  @ dynamic isininfo;  

It works fine, but if the user accidentally forgets to put in the @ dynamic line, the compiler automatically identifies the same @ synthesis line will not be a warning, but of course my code will not be used for that property.

I want to know that there is no way to disable self-property synthesis for this class. Thank you for answering Nikolai, I remember that to make the LLVM warnings promote errors and to wrap the declaration with that error, I can get the effect I was looking for (if the user If you forget to specify the @ dynamic line, then an error will be raised):

  // Make sure that we get an error, if we get an error For @ dynamic Do not forget to add property # Pragya Clag Diagnostic Push # Prima Clag Diagnostic Error "-Webbank-Missing-Properties-Synthesis" @ Interface Preferences: Prap Reference @ Property (NonAtomatic, Assign) @ Property (Nonatomic, Assign) NSINtegger Presscount; @end #pragma clang diagnostic pop  

There is no way to do this by code .

There is a compiler warning (Xcode's build setting is controlled by "Unplayed Syntysized Properties", CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS ) but you have to manually set it to the implementation file, For this it is not really helpful.

Here's another idea: Change your implementation to add properties using a range on a PAPreferences rather than a subclass, then the compiler can not synthesize the accessories. And if @dynamic is unavailable.

  @interface PAPreferences (SynthesizedProperties) @property int foo; @end @implementationPAPreferences @end  

Result:

  & gt; Warning: The method 'Foo' is required to define property 'foo' - use @dynamic or provide a method implementation in this category  

Additionally (or instead of ) You can assimilate the property during runtime by detecting accidentally synthesized accessors and emitting a warning in this case.


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -