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 pass strings through viewcontrollers. Make therefore a segue between the two viewcontroller and named it for example "secondVC"

the when you want to switch to other view make this call

```
[self performSegueWithIdentifier:@"secondVC"];

```

and implement this method.

```
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"secondVC"]) {
    SecondViewController *second = (SecondViewController *)[segue destinationViewController];
    second.userString = self.user;
}
}

```
If the second viewcontroller is spawned from the first you could just create a delegate protocol and corresponding delegate so that either the first is delegate of the second or the second is delegate of the first:

Here is an example of a protocol which includes one method, notice the instance variable delegate is of type id, as it will be unknown at compile time the type of class that will adopt this protocol.

```
#import <Foundation/Foundation.h>

@protocol ProcessDataDelegate <NSObject>
@required
- (void) processSuccessful: (BOOL)success;
@end

@interface ClassWithProtocol : NSObject 
{
 id <ProcessDataDelegate> delegate;
}

@property (retain) id delegate;

-(void)startSomeProcess;

@end

```

Inside the implementation section for the interface defined above we need to do two things at a minimum – first synthesize the delegate instance variable and second, call the method defined in the protocol as needed (more on that in a moment).

Let’s look at a bare bones implementation of the ClassWithProtocol.m:

```
#import "ClassWithProtocol.h"

@implementation ClassWithProtocol

@synthesize delegate;

- (void)processComplete
{
  [[self delegate] processSuccessful:YES];
}

-(void)startSomeProcess
{
  [NSTimer scheduledTimerWithTimeInterval:5.0 target:self 
    selector:@selector(processComplete) userInfo:nil repeats:YES];
}

@end

```

Read more at [this tutorial](http://iosdevelopertips.com/objective-c/the-basics-of-protocols-and-delegates.html)