Objective-C 01 _ basic syntax

Source: Internet
Author: User
Based on the C language, a layer of minimal object-oriented syntax is added
Fully compatible with C language
C language code can be mixed in oc code, even C ++ code
Can use oc to develop applications for Mac os X platform and ios platform
 
File extension: .m
 
1.Keyword
    Basically all keywords start with @
    Here are some common keywords:
    @interface, @implementation, @end
    @public, @protected, @private, @selector
    @try, @catch, @throw, @finally
    @protocol, @optional, @required, @class
    @property, @synthesize, @dynamic
    self, super, id, _cmd, _block, _strong, _weak
 
2. The string starts with @
    @ "Hello" is a string in OC (no space after @), "Hello" is a string in C
 
3. Other grammar
    Basic data types: char, int, float, double, BOOL (YES-1 \ NO-0) are all uppercase
    nil: equivalent to NULL in C, which is 0
    Basic statements: loop statements (do while, while, for), conditional statements (if, if-else, switch)
    Notes: // and /*..........*/
    Screen output: NSLog (@ "Hello"); NSLog (@ "age is% i", 27);
    
    NSLog: output content on the screen, automatically wrap after output
    If you want to use NSLog, you need to introduce the header file <Foundation / NSObjCRuntime.h>, and the function NSLog is declared in the NSObjCRuntime.h
    Foundation: framework, the most basic framework
        Each frame has a main header file, and the name of the header file is the same as the frame name
        The name of the main header file of the Foundation framework is Foundation.h
        Just need to include the main header file of the Foundation framework, you can use the entire framework of things
    Use #import to import header files in OC
        #import Purpose:
        1. Like #include, copy the file content
        2. The content of the house file can be copied repeatedly
 
    Path of Foundation framework header file
        1.Right-click Xcode.app-"The display contains content
        2.Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/System/Library/Frameworks/Foundation.framework
 
    When using #import to refer to a file, if it is a header file written by yourself, you can use #import "文件 .h"
 
working process:
    1> Write OC source files: .m, .c
    2> Compile: cc -c xxx.m xxx.c
    3> Link: cc xxx.o ddd.o -framework Foundation
        (Only the Foundation framework is needed to add -framework Foundation)
    4> Run: ./a.out
 
The difference between NSLog and printf
    NSLog receives OC strings as parameters, and printf receives C strings as parameters
    NSLog will automatically wrap after output, and printf will not automatically wrap
    Using NSLog requires #import <Foundation / Foundation.h>
    Using printf requires #include <stdio.h>
 
Common file extensions:
    .c C language source file
    .cc .cpp C ++ language source files
    .h header
    .m OC source file
    .mm OC ++ source file
    .pl Perl source files
    .o OC compiled file
 
return 0; By convention, 0 means that the program ends normally, and any non-zero value usually indicates that something went wrong.
Objective-C 01_Basic Syntax

Tags: style color io os use ar strong for file

Original address: http://www.cnblogs.com/yaofch107/p/3981776.html

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.