Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ClassHelper.h
- #import <Foundation/Foundation.h>
- @interface ClassHelperModel : NSObject
- + (NSDictionary*)getData:(NSString*)serverURL;
- @end
- -----------------------------------------------------------------------------------------------------------------------------------
- ClassHelper.m
- #import "ClassHelperModel.h"
- #import <AFNetworking/AFNetworking.h>
- NSDictionary *dataDict;
- @implementation ClassHelperModel
- + (NSDictionary*)getData:(NSString *)serverURL {
- NSString *dataAPILink = [[NSString alloc] initWithFormat:@"http://%@/data.php", serverURL];
- AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
- [manager GET:dataAPILink
- parameters:nil
- success:^(AFHTTPRequestOperation *operation, id responseObject) {
- dataDict = [[NSDictionary alloc] initWithDictionary:responseObject];
- // when i nslog here i can see the data
- NSLog("hello data : %@, dataDict");
- } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
- NSLog(@"data Error: %@", error);
- if (error) {
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"System Down" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
- [alert show];
- }
- }];
- // when i nslog here, i cannot see the data
- NSLog(@"hello world : %@", sebaranDict);
- return sebaranDict;
- }
- @end
- -----------------------------------------------------------------------------------------------------------------------------------
- MainVC.m
- #import "MainVC.h"
- #import "ClassHelperModel.h"
- @interface SebaranVC ()
- @property (strong, nonatomic) NSDictionary *dataDictionary;
- @end
- @implementation SebaranVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- // dataDictionary = [[NSDictionary alloc] init];
- dataDictionary = [ClassHelperModel getData:@"127.0.0.1"];
- // I got null here, IDK why :(
- NSLog(@"Data Dictionary: %@", dataDictionary);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement