39 of iOS development notes--a crash problem caused by a @dynamic

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.