ios - How can I pass a NSMutableDictionary value to multiple controllers in my storyboard? -
i have objective-c controller called linkedinlogincontroller
, inside have function contains nsdictionary called newresult shown below:
- (void)requestmewithtoken:(nsstring *)accesstoken { [self.client get:[nsstring stringwithformat:@"https://api.linkedin.com/v1/people/~?oauth2_access_token=%@&format=json", accesstoken] parameters:nil success:^(afhttprequestoperation *operation, nsdictionary *result) { nslog(@"current user %@", result); nsmutabledictionary *newresult = [result mutablecopy]; //copies nsdictionary 'result' nsmutabledictionary called 'newresult' [newresult setobject: [newresult objectforkey: @"id"] forkey: @"appuserid"]; //copies value assigned key 'id', 'appuserid' database can recognize [newresult removeobjectforkey: @"id"]; //removes 'id' key , value linkedinloginjson *instance= [linkedinloginjson new]; //calls linkedinpost method linkedinloginjson controller [instance linkedinpost:newresult]; } failure:^(afhttprequestoperation *operation, nserror *error) { nslog(@"failed fetch current user %@", error); } ]; [self performseguewithidentifier:@"tohottopics" sender: self]; //sends user on trending page after sign in linkedin }
i trying pass key value appuserid
4 different swift viewcontrollers. best way this? passing on segueway? tried calling directly nsdictionary using guide unsuccessful: http://mobiforge.com/design-development/using-objective-c-and-swift-together-ios-apps
fortunately obj-c , swift co-compatible @ moment (from understand).
in obj-c create new subclass of nsobject, maybe mysharedvalues, header this:
@interface mysharedvalues : nsobject @property (nonatomic, strong) id appuserid; +(instancetype)defaultinstance; @end
and implementation like:
@implementation +(instancetype)defaultinstance{ static mysharedvalues *obj = nil; static dispatch_once_t oncetoken; dispatch_once(&oncetoken, ^{ obj = [[self alloc] init]; }); return obj; } @end
then can import #import "mysharedvalues.h"
headers of controllers. access or set value, call
[mysharedvalues defaultinstance].appuserid;