iOS pen question collection (continuous update)

Source: Internet
Author: User

iOS Development written questions

One, OC Grammar part:

1, the meaning of description attribute in NSObject, can it be rewritten?

    • Example of usage : Defining a Person class, declaring two member variables

@interface Person: NSObject

{

nsstring * name;

int age;

}

    • In the implementation of the class, the Init method initializes the member variable

@implementation person

-(Instancetype) init

{

self = [super init];

if (self) {

name = @ " Lao li ";

age = ;

}

returnself;

}

    • To override the description method:

-(nsstring *) description

{

return [nsstring stringwithformat:@ " name:%@, Age:%d ", Name,age];

}

    • When this class is used, a person object is instantiated and the description method is automatically called when the object is log.

Person * Laoli = [ person new];

NSLog (@ "%@", Laoli);

    • The output results are as follows:

Name: Lao Li, Age: -

    • Here's the description method that acts as a description object:
    • If the description method is not overridden, the direct NSLog (@ "%@", Laoli) is obtained, and the output result is the class and memory address that the object belongs to:

      <Person:0x10010bbd0>

 

2.

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.