だから私はプロジェクトのために Twitter API (とりわけ) の上にレイヤーを構築しようとしており、Twitter アクションの結果を抽象化レイヤーに返す方法を見つける必要があります。
現在、私のセットアップは次のようなものです。たとえば、次のようになります。
-(NSDictionary *)sendTweet:(Tweet *)tweet {
__block NSMutableDictionary *responseDictionary;
NSLog(@"Sending tweet");
NSMutableDictionary *twitterRequestDictionary = [[NSMutableDictionary alloc] init];
[twitterRequestDictionary setObject:tweet.tweetBody forKey:@"status"];
TWRequest *request = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"https://api.twitter.com/1/statuses/update.json"]
parameters:twitterRequestDictionary
requestMethod:TWRequestMethodPOST];
[request setAccount:self.userAccount];
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
responseDictionary = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:nil];
NSLog(@"Response dictionary: %@", responseDictionary);
return responseDictionary;
}];
}
しかし、'performRequestWithHandler:' メソッドが 'void' を返すため、最後の行でエラーが発生します。
また、この記事を発見した後、「return」ステートメントをブロックの外に配置し、コードのブロック セクションの実行をロックしようとしました: http://omegadelta.net/2011/05/10/how-to-wait- for-ios-methods-with-completion-blocks-to-finish
まだ運がありません。
誰かがこの方法でそれを行う方法に光を当てることができることを願っています(または、データを返すためのより良い方法を提案するかもしれません)。