This repository has been archived by the owner on Jun 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 337
1.1 Objective C の基礎
tamotamago edited this page Apr 9, 2013
·
18 revisions
参考 : Objective-C プログラミング
NSObject *obj = [[NSObject alloc] init];
[obj exeWithArg1:hoge arg2:fuga]
Objective C にはメッソドにラベルがある。
MixiSampleClass.h, m を作成。
MixiSampleClass.h
#import <Foundation/Foundation.h>
// [1] 列挙詞
typedef NS_ENUM(NSInteger, SampleType){
SampleTypeHoge = 0,
SampleTypeFuga,
SampleTypePiyo
};
@interface MixiSampleClass : NSObject
@property (nonatomic, strong) NSString *name; //[2] property
-(id)initWithName:(NSString *)name; //[3] instance method
+(NSString *) getStaticString; //[4] class method
@end
MixiSampleClass.m
#import "MixiSampleClass.h"
static NSString *const constString = @"const"; // []クラス定数
static NSString staticString = @"static"; // []クラス変数
@interface MixiSampleClass()
@property (nonatomic, assign) BOOL isEnabled;
@property (nonatomic, assign) NSInteger number;
@end
@implementation MixiSampleClass
-(id)initWithName:(NSString *)name
{
self = [super init];
if(self){
_name = name; //[] access iVar
_isEnabled = YES;
_number = 0;
}
return self;
}
+ (NSString *)getStaticString
{
return staticString;
}
@end
- name というインスタンス変数を持っている(自動的に生成)
- nonatmic : 排他制御しない
- strong : オーナーシップをもっている
- -setName, -getName という getter, setter を自動的に生成。(getter=hoge, setter=fuga)と明示的に命名することも可能
インスタンスメソッドには - をつけて宣言
クラスメソッドには + をつけて宣言
- 自クラス内のインスタンス変数を参照、代入するときは _name = hoge, fuga = _name (self.name も可)
- 他クラスのインスタンス変数の場合は obj.name
はじめに
-
導入
-
1.3 UIViewController1 UIViewController のカスタマイズ(xib, autoresizing)
-
UIKit 1 - container, rotate-
-
UIKit 2- UIView -
-
UIKit 3 - table view -
-
UIKit 4 - image and text -
-
ネットワーク処理
-
ローカルキャッシュと通知
-
Blocks, GCD
-
設計とデザインパターン
-
開発ツール
-
テスト
-
In-App Purchase
-
付録