iOS注意事项

1.封装,继承,多态

Set:方法1.作用提供一个方法给外界设置成员变量的 命名规范

 作用:提供一个变量方法给外界设置成员变量值,可以在方法里面对参数进行相应的过

    set后面跟上成员变量的名称,成员变量的首字母必须大写

    一定要接收一个参数,而且参数类型跟成员变量类型一致

   形参的名称不能跟成员变量名一样

Get:方法

       返回对象内部的成员变量

      肯定有返回值,返回值类型肯定和成员变量类型一致,方法名跟成员变量名一致,不需要接    受任何参数

   #import <Fountation/Fountation.h>

@interfceStudent : NSObject

Int age;

}

-(void)setAge:(int)newAge;

@end

@implementationStudent

-(void)setAge:(int )newAge{

   if (newAge<= 0)

  {

   newAge =1; 

     }

   age =newAge;

}

-(void)study

{

  

   NSLog("%d 学生在学习"age);

 

 }

@end

Int main()

{

Student *stu =[Student new];

 

 [stu setAge:0];

[stustudy];

 }

2.对于字符一应该用单引号扩起来'Z'

   双引号表示一个字符串

3.类方法智能用类进行调用,当类方法用实例调用时,会出现闪退现象导致程序崩溃

4.对象方法不能用类对象调用,也会出现程序崩溃

5.两者的区别,类方法+开头,只能由类对象来调用

                              对象方法-开头,只能由对象来调用,两者可以重名,对象方法中能调用当前     对象的成员变量

//

//  main.m

//  yun

//

//  Created by qingyun on 15/7/27.

//  Copyright (c) 2015qingyun. All rights reserved.

//

 

#import <Foundation/Foundation.h>

 

@interface Score:NSObject

  {

      int _cscore;

      int _ocscore;

      int _totalscore;

      int _averagescore;

  

   }

-(void)setCscore:(int)cscore;

-(int) cscore;

-(void)setOcscore:(int)ocscore;

-(int)ocscore;

-(int)totalscore;

-(int)averagescore;

@end

@implementation Score

 

-(void)setCscore:(int)cscore

      {

          _cscore =cscore;

           _totalscore = _ocscore+_cscore;

           _averagescore = _totalscore/2;

           NSLog(@"_total value is %d\n",_totalscore);

      }

-(int)cscore

      {

          return _cscore;

      }

-(void)setOcscore:(int)ocscore

   {

       _ocscore=ocscore;

   }

-(int)ocscore

      {

          return _ocscore;

          }

-(int)totalscore

 {

  

      return _totalscore;

 }

-(int)averagescore

 {

      return _averagescore;

  }

 

@end

int main ()

 {

    Score *s =[Scorenew];

    [s setOcscore:100];

    [s setCscore:90];

     [s averagescore];

    int a = [s totalscore];

    

     NSLog(@"总分:%d",a);

    return 0;

 }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值