zoukankan      html  css  js  c++  java
  • Object-C——基础语法

    Object-C是在C语言的基础上加上了面向对象的部分,更好的来开发程序。

    一、 关键字

          1、基本上关键字都以@开头

           2、常见关键字如下:

    @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、

          3、字符串也以@开头

               如:@“hello”

    二、import

           #import的用途:

            1、跟#include一样,拷贝文件的内容

            2、 可以自动防止文件的内容被重复拷贝

    三、 Foundation

            1、开发iOS程序必备的框架,

             2、包含很多的API

             3、此框架包含了很多头文件

             头文件的引用

    #import <Foundation/Foundation.h>

    四、NSLog

             1、NSLog用来接受OC字符串座位参数

             2、NSLog输出后会自动换行

             3、使用NSLog 需要#import<Foundation/Foundation.h>

    五、Bool

             Bool类型的变量有2种取值:YES、NO

             举例

     1 #import <Foundation/Foundation.h>
     2 
     3 
     4 BOOL test(BOOL mybool)
     5 {
     6     return NO;
     7 }
     8 
     9 int main()
    10 {
    11     BOOL b = YES;
    12     
    13     BOOL b2 = NO;
    14     
    15     BOOL b3 = 1; // YES
    16     
    17     BOOL b4 = 0; // NO
    18     
    19     
    20     NSLog(@"%d", test(YES));
    21     return 0;
    22 }

    六、编译链接方法

        1、 编写OC源文件:.m、.c

         2、在终端种使用以下过程:

                ①  编译:cc -c xxx.m xxx.c

                ②  链接:cc xxx.o xxx.o -framework Foundation

                (只有用到了Foundation框架才需要加上-framework Foundation)

                 ③  运行:./a.out

  • 相关阅读:
    android 14 进度条和拖动条
    android 13 5种click事件不同实现方式 比较
    android 12 click事件的不同实现方式
    android 11 模拟onclick 事件
    android 10 事件
    android 09
    android 08 AndroidManifest.xml
    android 07 22 23没看
    Linux常用命令last的使用方法详解
    Linux TOP命令 按内存占用排序和按CPU占用排序
  • 原文地址:https://www.cnblogs.com/gaizuojia/p/4356964.html
Copyright © 2011-2022 走看看