How to disable property auto-sync property in Xcode 5?

I wrote a library for automatically creating NSUserDefaults accessories based on the properties @dynamicyou declare in the "preferences" class (see PAPreferences ). You write the property in a .m file, for example:

@property (nonatomic, assign) BOOL hasSeenIntro;

and then add it to the .h file:

@dynamic hasSeenIntro;

This works fine, but if the user accidentally forgot to insert a string @dynamic, then the compiler will automatically generate an equivalent string @synthesize. There will be no warnings, but, of course, my code will not be called for this property.

I would like to know if there is a way to disable automatic synthesis of properties for this class only.

Update:

Thanks to Nicholas, I remembered that it is possible to promote LLVM warnings for errors and wrap the announcement with this error in order to achieve the effect that I was looking for (the error will be raised if the user forgets to specify the line @dynamic):

// Ensure we get an error if we forget to add @dynamic for each property
#pragma clang diagnostic push
#pragma clang diagnostic error "-Wobjc-missing-property-synthesis"

@interface Preferences : PAPreferences

@property (nonatomic, assign) BOOL hasSeenIntro;
@property (nonatomic, assign) NSInteger pressCount;

@end

#pragma clang diagnostic pop
+4
source share
2 answers

There is no way to do this with code.

There is a warning about the compiler (controlled by setting the Xcode assembly "Implicit Synthesized Properties", CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS), but you need to manually set this in the implementation file, so for your case this is not very useful.

: , PAPreferences . , @dynamic.

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

@implementation PAPreferences (SynthesizedProperties)
@end

:

> warning: property 'foo' requires method 'foo' to be defined - use @dynamic or provide a method implementation in this category

( ) .

+6

AFAIK , Xcode , @synthesize . Unrecognize.

0

Source: https://habr.com/ru/post/1538479/


All Articles