IOS学习笔记之二:Object C的简单应用(对比Java)

1.养成在方法和类的大括号后边加名称注释的习惯。

2.Objective-C does not support multiple inheritance。

3.继承是在interface里边做,implementation不管这个,只管实现或者重写。

4.super的使用,用于修改被继承类的基本域。例如

@implementation Circle
- (void)setFillColor:(ShapeColor)c
{
 if (c == kRedColor)
 {
  c = kGreenColor;
 }
 [super setFillColor: c];
} // setFillColor
5.关于implementation中私有方法的使用
    
    
@interface Tire : NSObject
@end // Tire
@implementation Tire
- (NSString *) description {
  return (@"I am a tire. I last a while.");
} // description
@end // Tire
可以直接在interface中不声明,然后在implementation中导入。
6.An accessor method is one that reads or changes a specific attribute for an object. 
例如:
    
    
@interface Car : NSObject
{
  Engine *engine;
  Tire *tires[4];
}
- (Engine *) engine;
- (void) setEngine: (Engine *) newEngine;
- (Tire *) tireAtIndex: (int) index;
- (void) setTire: (Tire *) tire atIndex: (int) index;
- (void) print;
@end // Car
7.方法分开写不是两个方法,而是一个方法分开写之后会更容易读一些
例如-(void) speak:(NSString) word toPerson:(NSString) name;
8.Source File Orgnization,dot-h-file 用来记录类的声明,dot-m-file用来记录实现的过程。
9.If you use .mm for the file extension, you’re telling the compiler you’ve written your code inObjective-C++, which lets you use C++ and Objective-C together. 
10.@class theClass;当在一个类的声明中需要用到另一个类的时候,可以用#import “theClass”,也可以用@class theClass;但是同时要注意,
    
    

Because we’re inheriting from these classes rather than just using pointers to the classes, we can’t use the @class trick intheir header files. 继承的时候不能用.

11.When you declare a method with the plus sign, you’ve marked the method as a class method.This method belongs to the class object (as opposed to an instance object of the class) and istypically used to create new instances. Class methods used to create new objects are calledfactory methods

12.+号方法是类方法,主要有两种用途,一种是创建事物,另一种是使用工具方法的时候,例如return。。。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值