"Object-c" Processing object: Description method, IsEqual method

Source: Internet
Author: User

The description method is an instance method of NSObject, and all classes that inherit the NSObject base class have that method. Used to "Describe the ego", when the method is executed, the system outputs self-describing information about the object. The description method provided by the NSObject class always returns the < class name: 16, if a more detailed description of the class is required, you need to define the description method yourself.
O-c determine whether two variables are equal by two methods: 1, using the = = operator 2, using the IsEqual method//
//MAIN.M
//IsEqual
//
//Created by Mac on 14-11-28.
//Copyright (c)yearsmac. All rights reserved.
//

#import<Foundation/Foundation.h>

intMain (intargc,Const Char* argv[]) {
@autoreleasepool{
//Insert code here ...
NSLog (@ "Hello, world!");

intit = $;
floatFL =65.0f;
// the output1represent True
NSLog (@ "and the65.0fAre they equal? :%d " , (it = = FL));
Charch =' A ';
//the output1represent True
NSLog (@ "and the' A 'Are they equal? %d ", (it = = ch));
nsstring* str1 = [NSString stringWithFormat:@ "Hello"];
nsstring* str2 = [NSString stringWithFormat:@ "Hello"];
nsstring* STR3 = [NSString stringWithFormat:@ "Hi"];
//the output0represent false
NSLog (@ "Str1and thestr2Are they equal? %d ", (str1 = = str2));
// the output1represent True
NSLog (@ "Str1isisequal str2? %d ", [str1 isequal:str2]);
//becauseNSDatewith theNSStringclass does not have an inheritance relationship,

NSLog (@ "str1 is equal str3?%i", [str1 ISEQUAL:STR3]);

}
return0;}
==>> 2014-11-28 19:12:29.006 isequal[2359:303] Hello, world!
2014-11-28 19:12:29.007 isequal[2359:303]
and the 65.0f Are they equal? : 1
2014-11-28 19:12:29.008 isequal[2359:303]
and the ' A ' Are they equal? 1
2014-11-28 19:12:29.010 isequal[2359:303] str1
and the str2 Are they equal? 0
2014-11-28 19:12:29.010 isequal[2359:303] str1
is isequal str2 ? 1
2014-11-28 19:12:29.011 isequal[2359:303] str1 is equal STR3? 0
Program ended with exit code:0

"Object-c" Processing object: Description method, IsEqual method

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.