How to get objects from inside a block and use it in another class or method?

makvalti

I'm beginner in ios. This is a simple code example with AFNetworking.

AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@"http://yourServerAddress.com/"]];
[httpClient setParameterEncoding:AFFormURLParameterEncoding];
NSMutableURLRequest *request = [httpClient requestWithMethod:@"GET"
                                                        path:@"http://yourServerAddress.com/example?name=foo"
                                                  parameters:nil];
[httpClient registerHTTPOperationClass:[AFHTTPRequestOperation class]];
    AFHTTPRequestOperation *operation = [httpClient HTTPRequestOperationWithRequest:request
                                        success:^(AFHTTPRequestOperation *operation, id responseObject) {


                                            NSLog(@"Response: %@", [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]);
                                        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                                            //-- This block gets invoked when the operation fails
                                            NSLog(@"Error: %@", error.localizedDescription);
                                        }];

The responseObject would be printed to the console, but my question is : How to get responseObject and use it in an another class or methods?

EDIT 1:

I'm tried to use a method :

- (void)responseFromBlock:(id)response {

NSLog(@"responseObject from the block : %@",response);

}

And i'm use it inside the block :

 [self responseFromBlock:responseObject];

But the answer is:

response object from the block : <7b226572 726f7222 3a7b2263 6f646522 3a313230 307d2c22 72657375 6c74223a 5b7b2263 6964223a 22313234 222c2263 6e616d65 223a2244 69766174 227d2c7b 22636964... 
Andrey Chernukha

It might look like this:

@interface YourClassDealingWithAFNetworking

@property (nonatomic, retain) id object;

@end

And then inside the block:

self.object = responseObject;

Now you've got it and can use it wherever you need

just don't forget to release it in dealloc:

self.object = nil;

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How to call a class method from inside same class method?

分類Dev

Java - How do I get a variable generated from within a method in one class to another class?

分類Dev

How to use connection from one class into another

分類Dev

How to call another method from another class in swift?

分類Dev

How to properly call a class method from within another method

分類Dev

How to access class method from another class in flutter?

分類Dev

How to Get element that inside another element by class in HtmlAgilityPack

分類Dev

use Winform Objects inside an Static Method

分類Dev

how to call method of one fragment from another fragment class in android

分類Dev

How do I call a class method from another file in Python?

分類Dev

How to call a method from another class on buttonclick of Android activity?

分類Dev

How to call on something from another class in Java and use it's Array?

分類Dev

How can I get a variable from another class in Java?

分類Dev

How to get value from elements and use it inside of javascript options

分類Dev

How to get static onScroll event values from CollectionView back to the calling ListFragment or use the values in non-static method in the class?

分類Dev

How to use a method from other class Java Android onClick?

分類Dev

how to get a value from anchor tag and use it for another function

分類Dev

Access a child method from another child class

分類Dev

Invoking a toString method from another class

分類Dev

ActionPerformed method not working from another class

分類Dev

How to get all values of objects inside array

分類Dev

How to use another class as a class template specialization

分類Dev

How to use an array from one method in another method without making it global in Java

分類Dev

Access method of private class inside static inner class from main()

分類Dev

Access method of private class inside static inner class from main()

分類Dev

How to get method address of a generic class method?

分類Dev

Going from Java to C++: how to use one custom class var within another custom class?

分類Dev

How to call a method of another class using codemodel

分類Dev

Remove Specific Item From Array With Class Objects Inside

Related 関連記事

  1. 1

    How to call a class method from inside same class method?

  2. 2

    Java - How do I get a variable generated from within a method in one class to another class?

  3. 3

    How to use connection from one class into another

  4. 4

    How to call another method from another class in swift?

  5. 5

    How to properly call a class method from within another method

  6. 6

    How to access class method from another class in flutter?

  7. 7

    How to Get element that inside another element by class in HtmlAgilityPack

  8. 8

    use Winform Objects inside an Static Method

  9. 9

    how to call method of one fragment from another fragment class in android

  10. 10

    How do I call a class method from another file in Python?

  11. 11

    How to call a method from another class on buttonclick of Android activity?

  12. 12

    How to call on something from another class in Java and use it's Array?

  13. 13

    How can I get a variable from another class in Java?

  14. 14

    How to get value from elements and use it inside of javascript options

  15. 15

    How to get static onScroll event values from CollectionView back to the calling ListFragment or use the values in non-static method in the class?

  16. 16

    How to use a method from other class Java Android onClick?

  17. 17

    how to get a value from anchor tag and use it for another function

  18. 18

    Access a child method from another child class

  19. 19

    Invoking a toString method from another class

  20. 20

    ActionPerformed method not working from another class

  21. 21

    How to get all values of objects inside array

  22. 22

    How to use another class as a class template specialization

  23. 23

    How to use an array from one method in another method without making it global in Java

  24. 24

    Access method of private class inside static inner class from main()

  25. 25

    Access method of private class inside static inner class from main()

  26. 26

    How to get method address of a generic class method?

  27. 27

    Going from Java to C++: how to use one custom class var within another custom class?

  28. 28

    How to call a method of another class using codemodel

  29. 29

    Remove Specific Item From Array With Class Objects Inside

ホットタグ

アーカイブ