Subscribed unsubscribe Subscribe Subscribe

@peccul is peccu

(love peccu '(emacs lisp cat outdoor bicycle mac linux coffee))

= Objective-C,iPhone appでの流儀

[2010-10-01 22:22:35]
>>>[objc]
>>>[iphone]

Objectibe-Cでクラス作ったのになんで使えないんだろうという話です.
初歩的すぎて恥ずかしいので,さらけ出すことにしました.

エラーログ

こんな出力になるわけですね.

2010-10-01 19:07:20.555 svmsample[15111:307] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[SVMTrain<0xf7fc> init]: cannot init a class object.'
*** Call stack at first throw:
(
	0   CoreFoundation                      0x33506ed3 __exceptionPreprocess + 114
	1   libobjc.A.dylib                     0x30412811 objc_exception_throw + 24
	2   CoreFoundation                      0x3350857b +[NSObject(NSObject) init] + 106
	3   svmsample                           0x000033d1 -[svmsampleViewController viewDidLoad] + 60
	4   UIKit                               0x3422482b -[UIViewController view] + 110
	5   svmsample                           0x0000303b -[svmsampleAppDelegate application:didFinishLaunchingWithOptions:] + 66
	6   UIKit                               0x341c7481 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 772
	7   UIKit                               0x341bd9e7 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 206
	8   UIKit                               0x34216fdd -[UIApplication handleEvent:withNewEvent:] + 1396
	9   UIKit                               0x34216901 -[UIApplication sendEvent:] + 44
	10  UIKit                               0x34216337 _UIApplicationHandleEvent + 5110
	11  GraphicsServices                    0x31b5f04b PurpleEventCallback + 666
	12  CoreFoundation                      0x3349bce3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 26
	13  CoreFoundation                      0x3349bca7 __CFRunLoopDoSource1 + 166
	14  CoreFoundation                      0x3348e56d __CFRunLoopRun + 520
	15  CoreFoundation                      0x3348e277 CFRunLoopRunSpecific + 230
	16  CoreFoundation                      0x3348e17f CFRunLoopRunInMode + 58
	17  UIKit                               0x341bd103 -[UIApplication _run] + 370
	18  UIKit                               0x341bb12f UIApplicationMain + 670
	19  svmsample                           0x00002fcb main + 70
	20  svmsample                           0x00002f80 start + 40
)
terminate called after throwing an instance of 'NSException'
プログラムはシグナルを受信しました:“SIGABRT”。

問題のコード

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	SVMTrain *train=[SVMTrain init];
	NSLog(@"trainMain returns %d",[train trainMain]);
}

こんな感じのコードを書いて,SVMTrain.{h|m}をこねくりまわしてました.

結論としてはallocしてないし,できてないし,そもそもなんかわかってなかったね.

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	SVMTrain *train = [[SVMTrain alloc] init];
	NSLog(@"trainMain returns %d",[train trainMain]);
}

学んだポイント

恥ずかしすぎて,当たり前すぎて調べにくかったのであえて記録に残しておきます.