LoginSignup
0
1

More than 1 year has passed since last update.

【ObjectiveC】 setValueについて

Last updated at Posted at 2017-06-19

# setValueについての理解を深めよう

そのままパラメータにぶっこむことができるsetValue

ViewController.h
#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@property (nonatomic,strong) NSString *testValue;

@end
ViewController.m
@interface ViewController () {
    NSString *_testValue;
}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
// インスタンス変数 "_testValue" の値を読み込む
    NSString *testValue = [self valueForKey:@"testValue"];
    _testValue = @"テスト";
    NSLog(@"testValue : %@",testValue);
    NSLog(@"_testValue : %@",_testValue);
    NSLog(@"self.testValue : %@\n",self.testValue);
    self.testValue = @"self.テスト";
    NSLog(@"testValue : %@",testValue);
    NSLog(@"_testValue : %@",_testValue);
    NSLog(@"self.testValue : %@\n",self.testValue);
    // インスタンス変数 "_testValue" に値 @"testValue" を書き込む
    // self.testValue にも値 @"testValue" が書き込まれる
    [self setValue:@"testValue" forKey:@"testValue"];
    NSLog(@"testValue : %@",testValue);
    NSLog(@"_testValue : %@",_testValue);
    NSLog(@"self.testValue : %@\n",self.testValue);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

使い道は徐々に紹介していきます

ログ

LOG
testValue : (null)
_testValue : テスト
self.testValue : テスト

testValue : (null)
_testValue : self.テスト
self.testValue : self.テスト

testValue : (null)
_testValue : testValue
self.testValue : testValue

関連記事

  • Objective-C

【About】(http://qiita.com/sunstripe) - サンストライプ


制作チーム:サンストライプ

sunstripe_logo.png
http://sunstripe.main.jp/

(月1WEBコンテンツをリリースして便利な世の中を作っていくぞ!!ボランティアプログラマー/デザイナー/イラストレーター/その他クリエイター声優募集中!!)

地域情報 THEメディア

THE メディア 地域活性化をテーマに様々なリリース情報も含め、記事をお届けしてます!!
https://the.themedia.jp/

ゼロからはじめる演劇ワークショップ

多様化の時代に向けて他者理解を鍛える

プログラミングワークショップ・ウェブ塾の開講!!!

様々なテーマでプログラミングに囚われずに取り組んでいきます。
詳しくはこちら ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
プログラミングサロン 月1だけのプログラミング学習塾

協力応援 / 支援者の集い

チーム:サンストライプ

プログラミングラボ

一緒にポートフォリオを作りませんか?現場の体験やそれぞれの立場から年齢関係なく作品を作りたい方々と一緒にチームを作って、作品を作っています。現場に行きたい人には、職場紹介や職場の体験や悩み相談なども受けております。
様々な職種からプログラミングの知識を得たい、デザインの知識を得たい、データーベースの知識を得たいという人が集まっております。
週1のミーティングにそれぞれの近況と作業報告して、たまにリモート飲み会などをしております!!

興味がある方は、DMに話しかけてみてください。

トラストヒューマン

http://trusthuman.co.jp/
私たちは何よりも信頼、人と考えてます。

「コンサルティング」と「クリエイティブ」の両角度から「人材戦略パートナー」としてトータル的にサポートします!!

キャリア教育事業
広域学習支援プラットフォーム『のびのび日和』
https://slc-lab.amebaownd.com/

#スポンサー募集

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1