zoukankan      html  css  js  c++  java
  • Object-C

    http://www.cnblogs.com/zhangweia/archive/2011/11/01/2231549.html

    1、 文件分为.h:定义接口,及其属性,方法说明。 .m :是实现类。

    2、 用户的类一般派生于NSobject ,类名首字母大写,实例名首字母小写。

    3、属性: 在Interface内定义,可加修饰符,@priavte,@protected(缺省),@public

    4、方法:定义前“-”表示实例方法,“+”表示类方法。

    5、类型是要加()。

    --------------------------------------------------------------------------------------

    1.

    头文件的格式:

     

    #import <Foundation/Foundation.h>

    @interface myclass : NSObject

    {
        int numerator;
        int denominator;
    }
    - (void)print;
    - (void) setNumberator : (int) n;
    - (void) setDenominator : (int) d;
    @end

    类实现的格式:

     

    #import "myclass.h"

    @implementation myclass

    - (void)print
    {
        NSLog(@"hello zwh!");
        NSLog(@"%i/%i",numerator,denominator);

    }
    - (void)setNumberator:(int)n
    {
        numerator = n;

    }
    - (void)setDenominator:(int)d
    {
        denominator = d;

    }
    @end

  • 相关阅读:
    面向对象之单例模式
    面向对象之元类
    面向对象高级1
    面向对象进阶2
    面向对象进阶1
    面向对象基础
    MySQL事务
    【应用容器引擎】Docker笔记
    【Spring Boot】三、嵌入式的Servlet容器
    MySQL优化分析
  • 原文地址:https://www.cnblogs.com/webglcn/p/4195003.html
Copyright © 2011-2022 走看看