Small instance of OC Error about Init method careless

Source: Internet
Author: User

Face every mistake you encounter

In a small instance project of a remote control car toy, I used a combination of the remote control to have a car object (has a) relationship, not an inheritance (is a) relationship.

Idea: The instantiation process of creating a car is written in the initialization method of the remote control

CONTROLLER.M:

 1 - (Instancetype) Initwith  2  3  self = [super Init];  4   ( Self) { 5  NSLog (@ "  remote initialization created   );  6  _car = [[Car alloc] init];  7   8  return   self;  9 } 

Note: Here's the Init method, I accidentally wrote the Initwith method. The original intent is to customize the initialization method passed in parameters ... Forget to change back to Init.

Then, when creating the Controller object, use [[Controller alloc] init]. The result is called by the parent class (Controller extends NSObject) Init method, so the breakpoint is not found in the wrong, to a method will automatically jump out of the end.

Correct just put the wrong initwith back to the Init method.

Small instance of OC Error about Init method careless

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.