7
私はライブラリを作成しているので、自分のメソッド内でAFNetworking呼び出しからの応答をカプセル化する必要があります。このコードは近い私を取得します。メソッド内のAFNetworkingから成功した失敗ブロックをラップする
MyDevice *devices = [[MyDevice alloc] init];
[devices getDevices:@"devices.json?user_id=10" success:^(AFHTTPRequestOperation *operation, id responseObject) {
... can process json object here ...
}
- (void)getDevices:(NSString *)netPath success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error)) failure {
[[MyApiClient sharedDeviceServiceInstance] getPath:[NSString stringWithFormat:@"%@", netPath]
parameters:nil success:success failure:failure];
}
しかし、私は)getDevices(に戻る前にある、getPathから返されたJSONオブジェクトデータを処理する必要があります。 私はこれを試してみた:
- (void)getDevices:(NSString *)netPath success:(void (^)(id myResults))success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error)) failure {
[[MyApiClient sharedDeviceServiceInstance] getPath:[NSString stringWithFormat:@"%@", netPath]
parameters:nil
success:^(AFHTTPRequestOperation *operation, id responseObject)
{
... can process json object here ...
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
... process errors here ...
}];
}
をしかし今はコールがgetDevicesに戻っはありません()。 getDevicesのjsonオブジェクトを処理するにはどうすれば完了時にブロックリターンを持つ&ですか? 私はブロックを初めて使うので、助けてくれてありがとう。
あなたはphix23ありがとう! "success(myResults);を追加するとgetPath()successブロックに渡すと、すべてが期待通りに機能します。超高速応答に感謝します。 - Dan – Dan
明快なコメントも気に入っています。機能性に重点を置いてきたが、これらの提案を最終版に組み込む予定である。 – Dan
swiftでこのgetDevices関数が必要です。それをswiftに変換することはできますか –