• 締切済み

Objective-Cの文法(ハット^)について

Twitter Frameworkの以下の例文: #import <Twitter/TWTweetComposeViewController.h> TWTweetComposeViewController *viewController = [[TWTweetComposeViewController alloc] init]; viewController.completionHandler = ^(TWTweetComposeViewControllerResult res) { if (~ において,4行目(if分の上の文)の"^"の意味がわかる方はいますでしょうか.XORではなさそうですし...

みんなの回答

  • harawo
  • ベストアンサー率58% (3742/6450)
回答No.1

iOS Developer Library https://developer.apple.com/jp/devcenter/ios/library/japanese.html この中の「Blocks プログラミングトピックス」というPDF書類をお読みください。

全文を見る
すると、全ての回答が全文表示されます。

関連するQ&A

  • Objective-C,viewが動作しない

    IBを使わないカメラアプリを作っています。 AppDelegate.m内のapplication didFinishLaunchingメソッド内で生成したwindowとviewはコンパイルして表示確認できたのですが、viewControllerで書いたUIImagePickerViewControllerのviewが出てきません。 そもそもviewController.mのloadViewメソッドやviewDidLoadメソッドが動いていません。(メソッド内にNSLogを書いてコンパイルしてもログに出ない) viewController.h #import <UIKit/UIKit.h> @interface CameraViewController : UIViewController <UINavigationControllerDelegate,UIImagePickerControllerDelegate> { @private UIImagePickerController* _imagePicker; } @property(nonatomic,retain) UIImagePickerController *imagePicker; @end viewController.m #import "CameraViewController.h" @implementation CameraViewController @synthesize imagePicker=_imagePicker; - (void)dealloc { [super dealloc]; } #pragma mark - View lifecycle - (void)loadView { [super loadView]; //UIImagePickerControllerの作成 if(![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){ return; } UIImagePickerController* imagePicker; imagePicker = [[UIImagePickerController alloc] init]; [imagePicker autorelease]; imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; imagePicker.allowsEditing=NO; imagePicker.delegate = self; //imagePickerのviewを最上部に [self presentModalViewController:imagePicker animated:YES]; //シャッターを切る [self.imagePicker takePicture]; } @end viewControllerが機能しない原因としてそういった可能性が考えられるのでしょうか? あれこれ調べてみましたが煮詰まっています。よろしくお願いします

  • objective-c 初心者です

    はじめまして。iphone アプリ開発を始めようと思い、まずは簡単なアプリからと人のまねをして時計アプリを書いております。http://www.slideshare.net/takuya0429/121216の43枚目のスライドを丸写しにしました。しかし、iPhoneシミュレーター(iphone 6.1)でシミュレーションしても真っ黒な画面が移されるだけで思うように機能しません。 なぜ機能しないかを考えられる範囲でご教授願いたい次第です。 環境はmacbook air 13inch にてXcode 4.6.3を使用しております。 以下に作成したコードを記載いたします。 // // ViewController.h // watch // // Created by motoyama kaoru on 2013/08/15. // Copyright (c) 2013年 motoyama kaoru. All rights reserved. // #import <UIKit/UIKit.h> @interface ViewController : UIViewController @property (weak, nonatomic) IBOutlet UILabel *timeLabel; @end // // ViewController.m // watch // // Created by motoyama kaoru on 2013/08/15. // Copyright (c) 2013年 motoyama kaoru. All rights reserved. // #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(update) userInfo:nil repeats:YES]; } -(void)update{ NSDate *now = [NSDate date]; NSDateFormatter *df = [[NSDateFormatter alloc] init]; [df setDateFormat:@"HH:mm:ss"]; self.timeLabel.text = [df stringFromDate:now]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end

  • objective-c のインスタンスについて教えていただきたいのですが

    初心者なのですみません。 ご存知の方教えていただきたいのですが、 例えばaインスタンスがbクラスをインスタンス化して bインスタンスがcクラスをインスタンス化して aインスタンスがcクラスをインスタンス化しないで bインスタンスがインスタンス化したcインスタンスに メソッド送信のようなことが したいのですがうまくいきません。 どのようにすればよいですか? よろしくお願いします (aインスタンスがcクラスをインスタンス化した場合、bインスタンスがcクラスをインスタンス化したものと同じもの(アドレスが同じ?)なものなのでしょうか?違いますよね?ようするにストレージクラスやNSDataなどインスタンスの中のデータを複数のインスタンスから取り出したいのです) 面倒でスミマセン。 以下は確認のために簡易的に作ったものです。 文字数多すぎなのでinterfaceは省きました #import "Aobject.h" #import "Bobject.h" #import "Cobject.h" @implementation Aobject - (IBAction)callb:(id)sender { id Bobj = [[Bobject alloc]init]; [Bobj make]; [Cobj log]; //ここでエラーが出ます(`Cobj' undeclared (first use in this function) (Each undeclared identifier is reported only once for each function it appears in.)) } @end //-------------------------------------- #import "Bobject.h" #import "Cobject.h" @implementation Bobject - (void)make { id cobj = [[Cobject alloc]init]; } @end //-------------------------------------- #import "Cobject.h" @implementation Cobject - (void)log { NSLog(@"ok"); } @end

    • ベストアンサー
    • Mac
  • 【Objective-C】プロパテイについて

    Objectiv-Cの勉強を始めたばかりの者です。 プロパテイの機能を理解する為に以下のようなプログラムを書きました。 例1)まずは、プロパテイを使わない例です。 ーーーーーーー data.h ーーーーーーー #import <Foundation/NSObject.h> #import <Foundation/NSString.h> @interface Data : NSObject { NSString* str; } - (void)setStr:(NSString* )arg; - (NSString*)retStr; @end ーーーーーーー data.m ーーーーーーー #import "Data.h" @implementation Data - (NSString*) retStr{ return str; } - (void)setStr:(NSString*) arg{ [arg retain]; [str release]; str = arg; } @end ーーーーーーー main.m ーーーーーーー #import <stdio.h> #import "Data.h" int main(void) { Data* data = [[Data alloc] init]; [data setStr:@"aaa"]; NSLog(@"%@",[data retStr]); return 0; } 例2)次に、プロパテイを使って例1を書き換えてみました。 ーーーーーーー data.h ーーーーーーー #import <Foundation/NSObject.h> #import <Foundation/NSString.h> @interface Data : NSObject { NSString* str; } @property (retain) NSString* str; @end ーーーーーーー data.m ーーーーーーー #import "Data.h" @implementation Data @synthesize str; @end ーーーーーーー main.m ーーーーーーー #import <stdio.h> #import "Data.h" int main(void) { Data* test = [[Data alloc] init]; test.str = @"hoge"; NSLog(@"%@",test.str); return 0; } 例2を実行した結果、以下のように出力されました。 2010-02-05 22:17:50.696 data[1583:903] *** __NSAutoreleaseNoPool(): Object 0x100001068 of class NSCFString autoreleased with no pool in place - just leaking 2010-02-05 22:17:50.698 data[1583:903] hoge @propertyのオプションを(retain) ではなく、(assign)に変更すると、 2010-02-05 22:30:02.271 data[1619:903] hoge と出力されて、期待した結果が得られるのですが、なぜretainではダメなのでしょう? また、assignでも例1のようなメモリ管理は自動的に行われているのでしょうか? 以上、ご指導の程、よろしくお願いいたします。

  • Objective-Cのメモリ管理

    はじめまして。 iphoneアプリを作っていてメモリ管理について不明な点があるので教えて下さい。 memoryViewController.h ============================================== #import <UIKit/UIKit.h> @interface memoryViewController : UIViewController { id obj; } @property(retain)id obj; @end =============================================== memoryViewController.mm(一部) =============================================== @implementation memoryViewController @synthesize obj; - (void)viewDidLoad { [super viewDidLoad]; self.obj = [[NSObject alloc] init]; NSLog(@"count = %d", [obj retainCount]); } =============================================== 下記の部分についてです。 self.obj = [[NSObject alloc] init]; 「self.」を付けた場合retainCountは2で、付けなかった場合retaionCountは1になります。 何故違ってくるのかが理解できません。 教えて下さい。

  • Obj-CでViewコントローラのラベルに表示する

    Objective-Cであるクラスから、特定のViewControllerのもつLabel要素へテキストを表示したく、色々試してみたのですが、うまく動作しませんでした。 詳しい方、ぜひアドバイスお願いします。 □やりたいこと クラス側から、ViewControllerの持つ要素を操作したい □テストで使用したコード test_buttonをクリックすると、lbl_mesへ文字列を表示する ----------------- ■classTest.h #import "helloViewController.h" ----------------- ■classTest.m #import "classTest.h" - (void) makeStr { helloViewController *hv = [[helloViewController alloc] init]; hv->lbl_mes.text = @"HELLO WORLD"; [hv release]; } ----------------- ■helloViewController.h #import "classTest.h" @interface helloViewController : UIViewController { @public IBOutlet UILabel* lbl_mes; } @property(nonatomic,retain) IBOutlet UILabel* lbl_mes; -(IBAction) test_button; ----------------- ■helloViewController.m #import "helloViewController.h" -(IBAction) test_button{ classTest *clst = [[classTest alloc] init]; [clst makeStr]; [clst release]; } よろしくお願いします。

  • iPhone SDK・Xcode・Objective-cでのプロジェク

    iPhone SDK・Xcode・Objective-cでのプロジェクト共通定数クラスの定義について はじめて質問させていただきます。内容に不足あればすぐ修正しますのでご指摘ください。 当方iPhone SDK・Xcode・Objective-cを利用してアプリ開発をしています。 経験はCが我流で10年ほど、仕事ではjavaをメインに使っております。 それでアプリケーション全体から参照する定数を定義したいのですが使い勝手がいまひとつでして皆さんにご教示願いたい次第です。 javaではAppConst.javaというクラスファイルを作ってpublic const int NUMBER_ROW = 1と書き、 あとは使う側でその定数クラスをインクルードしておけば、AppConst.NUMBER_ROWという風に呼び出せたかと思います。(社内のフレームワークのおかげかもしれませんが…) Objective-cでも同様にしようと以下のように定数クラス AppConstを作りました。 #import <Foundation/Foundation.h> @interface AppConst : NSObject { NSInteger NUMBEROFFONT; } @property (nonatomic, assign) NSInteger NUMBEROFFONT; -------- #import "AppConst.h" @implementation AppConst @synthesize NUMBEROFFONT; -(id) init { self = [super init]; if (self != nil) { NUMBEROFFONT = 5; } return (self); } @end しかしこのクラスですと、参照側でインクルードするだけではなく、定数クラスのインスタンスを作らないと定数にアクセスできません。 #import "AppConst.h" (NSInteger) testMethod { AppConst *appConst = [[[AppConst alloc] init] autorelease]; return appConst.NUMBEROFFONT; } 使う度にインスタンスを作るのは面倒ですしメモリとしてもよくないように感じます。 もっと賢いやりかたがあればよろしくご教示のほどお願いします。

  • Objective-C初心者です。コンパイルができません。

    Objective-C初心者です。コンパイルができません。 4月からC言語でプログラミングを学び始め、昨日からObjective-Cに手を出しました。 Mac OS X 10.6.4を使用中です。入門書に書いてあったコードをそのまま入力し、ターミナルからgccによるコンパイルを行ったところエラーがでます。 どなたか原因が分かる方、アドバイスをお願いします。 以下具体的なコードです。←で指した行(2箇所)にエラーメッセージが出ています。 Objectを定義した正しいインクルードファイルがない、などが原因かなと考え調べて見たのですがどうもobjc/Object.hで問題なさそうなので打つ手がなく困っています。 #import <stdio.h> #import <objc/Object.h> @interface Test : Object ←error: cannot find interface declaration for 'Object', superclass of 'Test - (void) method ; @end @implementation Test - (void) method  { printf("Kitty on your lap\n") ; } @end int main() { id obj = [Test alloc] ;   ←warning: 'Test' may not respond to '+alloc' [obj method]; return 0; }

  • objective-cで困っています教えてください

    下記のようにUIViewの上にUIImageViewを配置し、そこにUIImageをUIViewContentModeScaleAspectFitで表示させています。 表示している画像タップして、座標をとりたいと考えています。 UIImageView(UIImage)上だけをタップのエリアにしたいのですが、画面全体がタップのエリアになってしまいます。また、画像のアスペクト比を維持しUIImageViewサイズに収まるように表示しているので、タップでとれたUIImageView上の座標と、画像上の座標にズレができてしまいます。UIImageViewサイズに収まるように表示された画像上の位置から元の画像の座標を取得する方法を教えてください。 #import "ViewController.h" @interface ViewController (){ UIImageView *imageView; } @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. CGRect rect = CGRectMake(0,20, 360, 480); imageView = [[UIImageView alloc] initWithFrame:rect]; imageView.backgroundColor = [UIColor redColor]; //画像のアスペクト比を維持しUIImageViewサイズに収まるように表示 imageView.contentMode = UIViewContentModeScaleAspectFit; UIImage *image = [UIImage imageNamed:@"hoge.png"]; [imageView setImage:image]; [self.view addSubview:imageView]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /** * タッチされたとき */ - (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { CGPoint p = [[touches anyObject] locationInView:imageView]; float x = p.x; // X座標 float y = p.y; // Y座標 NSLog(@"タップ開始 %f, %f", x, y); } @end

  • Objective-Cでのエラー

    よろしくお願いします。「Xcode5ではじめるObjective-Cプログラミング(大津真著)」という本を購入し、Objective-Cの勉強をはじめました。Objective-Cが初めてのプログラミング初心者です。 本に記載されたコードを入力しているのですが、下記でエラーが出て困っています。 何度も見なおしたのですが本との違いを見つけることができませんでした。 どこがおかしいのかお分かりの方がおられましたらどうか教えて下さい。 ●エラー more '%' conversions than data arguments が、下記の2箇所で出ます。(いずれも生年月日の前の@ に矢印がでています。) >NSLog(@"%@ 生年月日:%@, 身長:%.1fcm"), >NSLog(@"%@ 生年月日:%@, 身長:%.1fcm"), 実行すると Thread 1:EXC_BAD_ACCESS(code=EXC_1386_GPFLT) とでます。 ---------- // main.m #import <Foundation/Foundation.h> #import "Person.h" int main(int argc, const char * argv[]) { @autoreleasepool { Person *personA = [[Person alloc]init]; [personA setName:@"吉田一郎"]; NSDate *dateA = [NSDate dateWithString:@"1979-11-12 00:00:00 +0900"]; [personA setBirthday:dateA]; [personA setHeight:180.5]; NSLog(@"%@ 生年月日:%@, 身長:%.1fcm"), [personA name], [personA birthday], [personA height]; Person *personB = [[Person alloc]init]; [personB setName:@"山田太郎"]; NSDate *dateB = [NSDate dateWithString:@"1981-03-01 00:00:00 +0900"]; [personB setBirthday:dateB]; [personB setHeight:172.3]; NSLog(@"%@ 生年月日:%@, 身長:%.1fcm"), [personB name], [personB birthday], [personB height]; } return 0; } ---------- // Person.h #import <Foundation/Foundation.h> @interface Person : NSObject -(void)setName:(NSString *)name; -(NSString *)name; -(void)setBirthday:(NSDate *)birthday; -(NSDate *)birthday; -(double)height; -(void)setHeight:(double)newValue; @end ---------- // Person.m #import "Person.h" @implementation Person { NSString *_name; NSDate *_birthday; double _height; } -(void)setName:(NSString *)aName { _name = aName; } -(NSString *)name { return _name; } -(void)setBirthday:(NSDate *)aBirthday { _birthday = aBirthday; } -(NSDate *)birthday { return _birthday; } -(void)setHeight:(double)aHeight { _height = aHeight; } -(double)height { return _height; } @end

このQ&Aのポイント
  • スマホ(Android)から年賀状の宛名印刷をしたいが印刷が進まない問題について
  • A4用紙に写真印刷はできるが年賀状印刷ができない問題について
  • 対処方法を知りたい場合は詳しい方にアドバイスをお願いしたい
回答を見る