标签:
协议:
@protocol protocolName<protocol,…>
requiredMethodDeclarations //默认是被@required修饰
@optional
optionalMethodDeclarations
@required
requiredMethodDeclarations
@end
@interface XYPoint:NSObject<NSCopying>
–(id)copyWithZone:(NSZone *)zone //NSCopying协议中的正式方法
{
XYPoint *newPoint =[[XYPoint allocWithZone:zone] init];
[newPoint setX:x andY:y];//将旧对象的实例变量拷贝到新对象中
//x和y:是要拷贝的旧对象的实例变量
return newPoint;
}
分类试用范围:
分类中只能添加方法,不能添加实例变量。
分类中方法的优先级比原来类中的方法高。
标签:
原文地址:http://www.cnblogs.com/s-y-j/p/5757571.html