摘要:
1、字符串//======================================================================== /*字符串*/ NSString *s1 = [NSString stringWithFormat:@"You height is %d weight is %d",168,68]; NSLog(s1); NSLog(@"The str length is %lu",[s1 length]); NSString *s2 = @"You Height Is 168 we... 阅读全文
摘要:
1、Objc在使用alloc new copy 时为内存分配内存,然后返回分配的内存首地址存入指针变量,使用dealloc释放内存2、[[Fraction alloc] init] [Fraction new]是相同的3、main(){ A *a = [A new]; B *b = [B new]; c *c = [C new]; [b m:a]; [c m:a];}上述代码把a传递给了b 、c两个实例,而a实例本身又是在main函数中,因此一共有main函数、b 、c三个地方引用了a实例引出个问题,在alloc一个对象之后,什么时候dealloc它那?回收早了,可能导致有些还在引... 阅读全文
摘要:
Printing.h@protocol Printing1
-(void)print1;
@end @protocol Printing2
-(void) print2;
@end @protocol Printing3<Printing2>
-(void)print3;
@end
1、objc里的协议与java中的接口是同一个东西2、协议可以遵从协议2、说法:类Fraction遵从了Printing1、Printing3 //Fraction.h================================
#import <Foundation/Foundation.h 阅读全文
摘要:
1、id类型// Complex.h==============================
#import <Foundation/Foundation.h> @interface Complex : NSObject{ double real; double imageinary;
} -(Complex*) initWithReal:(double) r andImageinary:(double)i;
-(void)setReal:(double) r;
-(void)setImaginary:(double) i;
-(void)setReal:(double)r a 阅读全文
摘要:
MyRectangle.h//==========================================
#import <Foundation/Foundation.h> @interface MyRectangel:NSObject{ int width; int height;
} -(MyRectangel*) initWithWidth:(int) weight andHeight:(int) height;
-(void) setWidth:(int) width;
-(void) setHeight:(int) height; -(int)width;
-( 阅读全文