Objective C notes (first day)

Source: Internet
Author: User

OC Language Overview

1. Early in the the 1980s, Bard Cox invented the objective C, an expanded C, object-oriented programming language.

2.NEXTSTEP abbreviation NS

Steve Jobs became the next company in a.1985 years.

b.1988, NeXT Software acquired OC's language authorization, NEXTSTEP environment became the Apple operating system, created the development package. MACOS

c.1996, December 20, Apple announced the acquisition of next software, the NEXTSTEP environment is the basis for Apple's main development and operating OS OSX, a version of which was named Cocoa (cocoa) framework by Apple.

NSString Ns=nextstep

3. Cocoa Framework

A.cocoa is the native object-oriented programming environment that Apple created for Mac OS X.

B.cocoa applications are generally written in Objective C on Apple's tool Xcode.

C. Applications developed using the Cocoa programming environment are called cocoa. app->application-> applications

Cocoa Touch Frame->ctapp

The D.COCOA framework consists mainly of two parts, the Fundation framework and the application Kit framework.

E.fundation Framework, basic framework, including: strings, numbers, arrays, dictionaries, collections, etc.

#import <Foundation/Foundation.h>

The F.application kit framework, the Application Toolbox, includes all objects for implementing program graphics, event drivers, and user interfaces, Windows, dialogs, buttons, menus, scroll bars, text boxes, and so on, and this list is constantly being added.

4.IOS

An operating system on Apple's hardware, an operating system on Apple's portable device. On January 9, 2007, the system, unveiled at the Macworld Conference, was originally designed for the iphone and later used Apple products such as Ipodtouch, ipad and Apple TV.

• Syntax formatting differences

1. The include used in the C language is now replaced with import, which is similar to the C language include and must be replaced with import, and supports avoiding duplicate import issues.

2. The printf function used in the C language before to output, print, now for the NSLog function, log output, pay attention to the output string information, to add @ at the top, do not need to use \ n as a line break.

3. At compile time, although GCC can compile, but does not support the new OC syntax, the source file from the original. c file, into the. m file.

4. At compile time, using the new Compile command clang, when compiling the link, you need to specify the framework (library) to use.

Clang-framework Foundation main.m

5. a.out file is still generated after compiling, you can use./a.out to run the program.

Include and import

#import <> or "" and #include<> or "", OBJC all the files contained in the instructions are used #import<> or #import "" to achieve, you can avoid the header file is repeated, Automatic culling of duplicate header files, if you want to use #include <> or "" need to be implemented by #ifndef conditional compilation.

• Logical data type bool

A.bool B1 = false;//true 1,flase 0

B.bool b2 = Yes;//yes 1,no 0

Object-oriented concepts

• What is Object-oriented program development

1. Process-oriented data structure + algorithm

2. Object-oriented properties + behavior

• Why use object-oriented programming ideas

The use of object-oriented programming ideas can greatly reduce the development cycle and cost of enterprise projects, improve the efficiency of development, and the reusability of code, greatly reducing the difficulty of development. Improved readability and maintainability of the code.

• Object

Anything is object. Everything objects. In reality, the object is an objective existence, the object in the program is the data in the memory of the chip.

• Objects in the real world

Student objects in the real world

What's the name and age to do? study

Attribute (member): Age,name

Method (function) study ()

Solve the problem of computer by solving the problems in reality.

• What is a class

The generic name of the same class of elements that have the same properties and methods.

Class is an abstract concept, such as: Human animal vegetable and fruit car, when distinguishing between a class or an object, see if it can continue to be subdivided. Objects cannot continue to be subdivided. A class is an abstraction of a real thing.

Design (drawings) (Dream)---factory production---> Mobile phone (Reality)

Code (file)---Perform load---> Memory (data)

Class---instantiating---> objects

• Define the syntax format of a class

The design class student code exists in the file, OC class. A class is a two-part *.h. File and *.m? file

1). h file defines the interface part of the class (declaration)

@interface Student:nsobject

@property int age;//DECLARE properties!

-(void) study;//declaration? Method!

@en

2). M. implemention part of the file definition class (Implementation)

@implementation the definition and implementation of the student//Method!

-(void) study{

"NSLog (@" Students performed the study method ");

}

@end

. What is an object

An object is an instance of a class in memory. An object is a concrete object of a class. It is not subdivided, it represents a specific thing.

• Instantiating a class into an object

1)->main function (program port) execution procedure in MAIN.M

2) can send Alloc, through a class to create objects, through the STU variable (*stu), find the object of memory.

3) a message (function) can be sent to the object, at which point the object responds to the message and executes the method.

4) Object If there is an attribute, object. property = value, assigning a value to an object's properties

. method

• What is a method object can do and what function it has.

• Method and Function differences

A function is just a code snippet of a program that has no relation to a class.

A method is a part of a class that represents what an object can do.

Normally, a class must be instantiated, a method can be used, and an instance method calls a method when it is called to send a message to an object.

• Method naming syntax format is very similar to a function, but it is very different. When you use a method, it is declared in the. h file and implemented in the. m file.

-(return value type) method name; Non-parametric method

eg:-(void) method;

• Parameters of the method

-(return value type) method Name: (parameter type) parameter name;//method of argument

eg:-(void) method3: (int) num;

-(return value type) method name: (parameter 1 type) parameter name 1:(parameter 2 type) parameter name 2:(parameter n type) parameter name n;//multi-parameter method

eg:-(void) method4: (int) arg1:(int) arg2; Note: the ":" Symbol is also the method name? section

• Parameters of the method

-(return value type) Part of method name: (parameter 1 type) parameter Name 1 part method Name 2: (parameter 2 type) parameter Name 2 part method name N: (parameter n type) parameter name N; Some method names act as a hint, and do not affect the execution of the program

eg:-(void) printinfowithage: (int) age!

Andgender: (char) gender!

Andsalary: (double) salary;

The return value of the method

The function return values in the C language are used in the same way.

• Public and private methods

The methods declared in the. h file, and implemented in. m files, are public methods.

Methods that are not declared in the. h file and implemented in. m files are private methods.

Instance variable

• What are member variables and instance variables

A variable declared in a class is a member variable. When a class instantiation becomes an object, the member variable becomes an instance variable. An object has its own unique data that is different from other objects, which are stored in special variables called instance variables.   Each instance (object) of the class has one copy. Class object (instance) (reference)

There is no memory in memory

Member variable Instance variable

Member Method Instance method

• Define variables in the. h file, using the zone declaration enclosed in {}, a variable declaration of Type C language.

• Public and private variables the variables declared in the. h file are public variables, and the variables declared in the. m file are private variables

Objective C notes (first day)

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.