Question: I currently have a class and ViewController with a button action to get the username and password from a textfield and put them into their own NSString. I then use the NSString to perform a post request like so.

```
NSString *user = _username.text;
    NSString *password = _password.text;

    AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@"http://thesite.com/login.php"]];
    [httpClient setParameterEncoding:AFFormURLParameterEncoding];
    NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST"
                                                            path:@"http://thesite.com/login.php"
                                                      parameters:@{@"username":user, @"password":password}];
    AFHTTPRequestOperation * httpOperation = [httpClient HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {
        //success code
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        //error handler
    }];
    [httpClient enqueueHTTPRequestOperation:httpOperation];

```

However I have another class and Viewcontroller to perform a get request. However, in order to perform this get request I need to get the "NSString \*user" from the first View Controller. How would I go about doing this? Should I declare a NSString \*user in the header of the first Viewcontroller and then in the second View controller declare an instance of the first class?

Answer: 
You can use [NSUserDefaults](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/nsuserdefaults_Class/Reference/Reference.html) to store the username and use it in other ViewControllers.

For example, save it in your current ViewController.

```
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:username forKey:@"UserName"];
[defaults synchronize];

```

get username it in another ViewController.

```
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *username = [defaults objectForKey:@"UserName"];

```
Create object of first class in second class like this..

//First class

//Pass the values to seconClass

```
secondClass *appdelegate = [NSApp delegate];
[appdelegate initwithDetails:userName withPassword:password];

```

//Second class

//In second class declare the function and get the values

//When u create the object, init function will call first

```
-(id)initwithDetails:(NSString *)user withPassword:(NSString *)password 
{
    userName = [NSString stringWithFormat:@"%@", user];
    newPass=[NSString stringWithFormat:@"%@", password];
    return self;
}

```