Advertisement
Guest User

nslog return null

a guest
May 27th, 2015
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. ClassHelper.h
  2. #import <Foundation/Foundation.h>
  3.  
  4. @interface ClassHelperModel : NSObject
  5. + (NSDictionary*)getData:(NSString*)serverURL;
  6. @end
  7. -----------------------------------------------------------------------------------------------------------------------------------
  8.  
  9. ClassHelper.m
  10.  
  11. #import "ClassHelperModel.h"
  12. #import <AFNetworking/AFNetworking.h>
  13.  
  14. NSDictionary *dataDict;
  15.  
  16. @implementation ClassHelperModel
  17. + (NSDictionary*)getData:(NSString *)serverURL {
  18. NSString *dataAPILink = [[NSString alloc] initWithFormat:@"http://%@/data.php", serverURL];
  19. AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
  20. [manager GET:dataAPILink
  21. parameters:nil
  22. success:^(AFHTTPRequestOperation *operation, id responseObject) {
  23. dataDict = [[NSDictionary alloc] initWithDictionary:responseObject];
  24. // when i nslog here i can see the data
  25. NSLog("hello data : %@, dataDict");
  26. } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
  27. NSLog(@"data Error: %@", error);
  28. if (error) {
  29. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"System Down" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
  30. [alert show];
  31. }
  32. }];
  33.  
  34. // when i nslog here, i cannot see the data
  35. NSLog(@"hello world : %@", sebaranDict);
  36. return sebaranDict;
  37. }
  38. @end
  39. -----------------------------------------------------------------------------------------------------------------------------------
  40. MainVC.m
  41.  
  42. #import "MainVC.h"
  43. #import "ClassHelperModel.h"
  44.  
  45. @interface SebaranVC ()
  46. @property (strong, nonatomic) NSDictionary *dataDictionary;
  47. @end
  48.  
  49. @implementation SebaranVC
  50. - (void)viewDidLoad {
  51. [super viewDidLoad];
  52. // Do any additional setup after loading the view.
  53.  
  54. // dataDictionary = [[NSDictionary alloc] init];
  55. dataDictionary = [ClassHelperModel getData:@"127.0.0.1"];
  56. // I got null here, IDK why :(
  57. NSLog(@"Data Dictionary: %@", dataDictionary);
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement