私はCocoaを初めて使用するので、使用しているスタイルとコードが自分の目的に適した形式であることを確認したいと思います。
特にヘッダー(マークa)
)では、変数を?の外に設定するとどのような影響があり@interface
ますか?
b)
そして第二に、クラス宣言内に登録せずにインスタンスから(ある時点で)変数を使用することの効果は何ですか?
ヘッダーファイル:
#import <UIKit/UIKit.h>
///////////// a) Is this good use?
int myint;
/////////////
@interface InstancecheckViewController : UIViewController
- (IBAction)plusone:(id)sender;
@property (weak, nonatomic) IBOutlet UILabel *counting;
@end
実装:
#import "InstancecheckViewController.h"
@interface InstancecheckViewController ()
@end
@implementation InstancecheckViewController
@synthesize counting;
///////////////////// b) is this good use?
- (void)resetit {
myint = 0;
}
/////////////////////
- (IBAction)plusone:(id)sender {
myint ++;
if (myint >10){
[self resetit];
}
NSString* myNewString = [NSString stringWithFormat:@"%d", myint];
counting.text = myNewString;
}
@end
編集
コメントありがとうございます。.hのインスタンスと整数を適切に再定義したと思います
@interface instancecheckViewController : UIViewController
{
@private
int myint;
}
- (IBAction)plusone:(id)sender;
- (void)resetIt;
@end