クラスつくって、
プロパティで、セッターゲッターをする方法。


#import


@interface Test : NSObject {
NSString *name;
double height;
NSString *highSchool;

}

//名前のセッターゲッター
-(void) setName:(NSString *) name;
-(NSString *) name;

//身長のセッターゲッター
-(void) setheight:(double) height;
-(double)height;

//計算後のゲッタ
-(double) stdWeight;

@property NSString *highSchool;

@end
------------------------------------------------------------------------------------------------
#import "test.h"


@implementation Test

@synthesize highSchool;

//名前のゲッター
-(void) setName:(NSString *) n{
NSLog(@"%sをセットします",n);
name = n;
}

//名前のゲッター
-(NSString *) name{
NSLog(@"%sを返します",name);
return name;
}

//身長のセッターゲッター
-(void) setheight:(double) h{
NSLog(@"%dをセットします",h);
height = h;

}
//身長のセッターゲッター
-(double)height:h{
NSLog(@"%dを返します",h);
return height;
}

//計算後のゲッタ
-(double) stdWeight{
NSLog(@"%sと%dを計算式を返します",name,height);

return 0;
}


@end
#import
#import "Test.h";


int main (int argc, const char * argv[]) {

// insert code here...
NSLog(@"Hello, World!");


//testをよぶ
Test *t = [[Test alloc]init];
//いろんな呼び方
[t setName:"tamura"];
[t height :156];
t.name = "takeshi";
t.highSchool = "ichikou";

//いろんな取得(セッターゲッターあるほう)
NSLog(@"結果=%d",t.stdWeight);
//いろんな取得(プロパティのほう)
NSLog(@"高校は%s",t.highSchool);
return;
}
macめも
白抜き上矢印の意味がわからなかったが、
SHIFTをおしながらということがわかった。

キーでなんでもやってしまう癖があるので、
これを知れたのは大きい!

ほんと初心者。
ひさしぶりの更新。

ここんとこ、夜遅く帰っていたから、
プログラムできなかった。

ひとつセミナーをうけて、
プログラムを写経することもいいというのをきいた。

これから、俺も座学ではなく、
ひとまず、真似して、少しアレンジしていく、
そういうのを続けてみようと思う。

その第一歩。

日付の処理。


NSDate *now;
NSString *nowstr;
NSString *nowstr2;

//インスタンス生成&初期化
now = [[NSDate alloc]init];
//現在のロケール取得
NSLocale *locale = [NSLocale currentLocale];
//文字列で取得
nowstr = [now descriptionWithLocale:locale];

NSLog(@"今何時?%@",nowstr);
//文字列で取得
nowstr2 = [now descriptionWithLocale:[NSLocale currentLocale]];

NSLog(@"これもあり。今何時?%@",nowstr2);

NSDate *now2;
now2 = now;

NSLog(@"これポインタを代入。今何時?%@",[now2 descriptionWithLocale:[NSLocale currentLocale]]);

NSDate *old;
old = [[NSDate alloc]initWithString:@"1977-09-24 00:00:00 +0900" ];

NSLog(@"あのとき何時?%@",old);

//1977-09-24から今までの秒をもつ。
NSTimeInterval diff = [old timeIntervalSinceNow];
double diffYear = diff /60 /60 /24 /365;
NSLog(@"今まで、%1.f秒",diff);
NSLog(@"今まで、%1.f分",diff /60);
NSLog(@"今まで、%1.f時間",diff /60/60);
NSLog(@"今まで、%1.f日",diff /60/60/24);
NSLog(@"今まで、%1.f年",diffYear);