Objective-c Description Method Sel type

Source: Internet
Author: User

Description method

#import "Person.h"@implementation Person- (void) Setage: (int) Age {_age=Age ;}/** Determines the output result of the instance object **/-(NSString *) Description {return[NSString stringWithFormat:@"age=%i", _age];}/** Determines the output of the class object **/+ (NSString *) Description {return @"ABC";}@end//By default (not overridden) when you use the NSLog and%@ output objects, the result is: < class name: Memory address >//the-description method that invokes the object//get the return value of the-description method (NSString *) displayed on the screen//The -description method returns the "class name + memory address" by default;//easy to observe results general override the-description method of the parent class

SEL type

1. Where to store the method

The list of methods for each class is stored in the class object

Each method has an object of the corresponding SEL type

You can find the address of the method based on a Sel object and then call the method

Creation of 2.SEL objects

SEL s = @selector (method name);

SEL s2 = nsselectorfromstring (@ "Test");

Other uses of 3.SEL objects

Convert Sel object to NSString Object

NSString *str = Nsstringfromselector (@selector (method name));

According to Sel tuning method

[P Performselector: @selector (method name)];

[P Performselector: @selector (method name) Withobject: actual parameter];

[Self performselector: _cmd]//will trigger a dead loop _cmd represents the current method

Objective-c Description Method Sel type

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.