1, the recent good engineering code suddenly emerged a crash Bug,a class crash log as follows:
2015-06-03 11:42:53.807 dpscope[86379:1639651]-[a Settitlecell:]: Unrecognized selector to sent instance
2015-06-03 11:42:53.815 dpscope[86379:1639651] * * * terminating app due to uncaught exception ' Nsinvalidargumentexception ', Reason: '-[a Settitlecell:: Unrecognized selector to sent instance '
* * * Throw Call Stack:
(
0 corefoundation 0x0000000112203c65 __exceptionpreprocess + 165
1 LIBOBJC. A.dylib 0x0000000111e9abb7 Objc_exception_throw +
2 corefoundation 0X000000011220B0AD-[ NSObject (NSObject) Doesnotrecognizeselector:] + 205
3 corefoundation 0x000000011216113c ___ forwarding___ + 988
4 corefoundation 0X0000000112160CD8 _cf_forwarding_prep_0 + 120
The general meaning of the crash log is that the method of Settitlecell is not found;
And Titlecell is a cell property of Class A,
@property (Nonatomic,strong) Titlecell *titlecell;
It was later found that the Titlecell attribute was declared as follows when implemented:
@implementation A
@dynamic Titlecell;
Comment out this line of code, no longer crash.
2, @dynamic keyword and the use of @synthesize key words
When a @property attribute is @synthesize decorated, it means that if you do not manually implement the setter and getter methods of the property, then the compiler cocktail party automatically generates them for you;
When a @property attribute is @dynamic decorated, it means that the getter and setter method of the attribute needs to be implemented by the user itself and not generated automatically. If you do not manually provide a setter or getter method, then the compile time is OK, but when the program runs like Self.titlecell= [Titlecell new] or Titlecell *cell = Self.titlecell, Is crash by the lack of setter methods and getter methods. Compilation is no problem, the runtime will execute the appropriate method, is called the dynamic binding mechanism.
Of course, if you do not show them, default is @syntheszie way;
3, reference links
http://blog.csdn.net/haishu_zheng/article/details/12873151