[object-c 2.0 程序设计]object-c review (一)
// // main.m // cmdTry // // Created by Calos Chen on 2017/8/21. // Copyright © 2017年 Calos Chen. All rights reserved. // #import <Foundation/Foundation.h> @class Fraction; @interface Fraction : NSObject { int numberator; int denominator; NSString* name; double price; Fraction *myf; } @property double price; -(void) print; -(void) setNumberator: (int)n; -(void) setName: (NSString*)na; -(void) setInfo: (int) id name:(NSString*)name; @end @implementation Fraction @synthesize price; -(void) print { NSLog(@"%i it is %@",numberator,name); } -(void) setNumberator:(int)n { price=5; numberator=n; } -(void)setName:(NSString *)na{ name=na; } -(void) setInfo:(int)id name:(NSString *)na{ id=id; name=na; } @end //---- program section ---- int main(int argc, const char * argv[]) { @autoreleasepool { // insert code here... NSLog(@"Hello, World!"); NSLog(@"who are you!"); } NSLog(@"why is it"); Fraction *myf= [[Fraction alloc] init]; [myf setName:@"calos"]; [myf print]; int a1=5; float a2=3.23; double a3=3.44; char a4='c'; int a5=(int)a2; for (int b=1; b<10;b++ ) { a5+=b; } myf.price=88; double b1=myf.price; BOOL isPrime=NO; NSLog(@"%i %f %e %c %i %c %g",a1,a2,a3,a4,a5,isPrime,b1); NSLog(@"end........"); return 0; } //for today: 2017-08-21, I have read and practiced the first 153 pages of the object-c 2.0, now, I have known object-c classes and data types, and how to announce and implement the classes and class members, as well as functions in the class implementation. also property synthesize methods. loops. //homework: implement a new class, and new interface and fill the class with members and all tangible members, then use all of them. @class declaration. So, write a console program with object-c.
今天在 object-c 方面取得了一定的进展, 既然不能左右时间,不如静心来好好打一番基础,感觉这个 oc 的基础是不会过时的. 现在已经能做到的是,object-c 的基本语法,类,数据类型,基本使用方法, 方法,属性,格式化等的声明.