Learn Objectvie-c on the MAC 2nd Edition notes

Source: Internet
Author: User
Tags time and date

Chapter 1
Apple's Cocoa (for OS X) and Cocoa Touch (for IOS) toolkits are written in objective-c.

Chapter 2

(1). M stands for "messages" abbreviation

  C compiler  -C + + compiler, M-object-C compiler  

(2) in Objective-c, #import guarantees that each header file is included only once, as the #ifdef header file defender in C does.

(3) NSLog () is like printf () in C, but adds time and date stamps and automatically adds "\ n" newline characters at the end of the line.

@ ("") means that the string in "" is treated as a nsstring unit. If the C-style string "" is used directly in NSLog and the @ () is missing, a warning is obtained at compile time and the runtime is crash.

(4) Type BOOL

In Objectvie-c, the bool type is a typedef that is actually a signed char, so not only can you use Yes (value =1) and no (value =0) to represent true and false in C, but other values can be stored. Here's a simple mistake: If you assign a value of type such as short or int to a bool variable, the end of the 8 bits is truncated, and if the 8-bit value at the end is exactly 0 (for example, 8960, its hexadecimal value is 0x2300), the bool value of this value is 0, which is no, not No.

Chapter 3

(1) Core idea of computer science: indirection. Instead of using a value dirctly in your code, use a pointer to the value; Instead of doing something by yourself, ask another person to do it.

(2) A file read example:

#import<Foundation/Foundation.h>intMainintargcConst Char*argv[]) {    if(ARGC = =1) {NSLog (@"You need to provide a file Name"); return(1). } FILE*wordfile = fopen (Argv[1],"R"); ARGV[0] is the code file pathCharword[ -];  while(Fgets (Word, -, Wordfile) {         //strip off the trailing \ nWord[strlen (Word)-1] =' /'; NSLog (@"%s Kis%lu characters long", Word, strlen (word));    } fclose (Wordfile); return(0).} //Main

(3) in Objective-c, the method call uses infix notation (infix notation), such as

[Circle Setfillcolor:kredcolor];

If a method has no arguments, there is no colon and argument list, and if there are arguments, there is a colon:

-(void/ / no parameter -(void//  parameter )

Chapter 6

(1) The Code of the Objective-c class can be divided into 2 parts:

1>. @interface section

@interface xx:yy{    variables;} Public method declarations. @end

Provides a public interface declaration for this class.

2>. @implementation section

@implementation XX private self-used methods@end

Provides an implementation of this class and an intrinsic function.

Learn Objectvie-c on the MAC 2nd Edition notes

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.