Passing data between segues without using PrepareForSegue

I am creating a user account with 5 steps using a storyboard. Each step has a ViewController: 1º) Login for name, contact, etc., 2º) Import photos, 3º) Login, etc. 4º) Additional inputs 5º) Confirmation page if user clicks "confirm" → Get all inputs and load syntax.

The only solution I get when I search the internet for this is to create a "Prepare for Segue" func and pass the information ... But it doesn't make any sense to me:

If I had 1000 view controllers, would the first view controller information go through all 1000 view controllers? Why didn't the nº1000 controller receive all the information that was left behind? eg: Viewcontroller nº50 does not need information about viewcontroller nº1 ... This is nonsense.

Is there any other way to implement this?

Maybe there is a solution, since I am using Parse, for example when I do:

ParseClass ["Name"] = textfield.text

It sends information to Parse and they hold it until I do something like SaveInBackground ().

I am trying to find a solution like this using viewcontrollers. Each view controller sends information to parse and store the information until "saveinbackground ()" occurs on Viewcontroller nº5.

Possible? thank


source to share

3 answers

Yes it is possible. You can use NSUserDefaults

for what will keep your information in memory, and once it is saved, you can use it anywhere in your project.

How can you store the value with it like this:

NSUserDefaults.standardUserDefaults().setObject(yourObject, forKey: "yourKey")


You can now retrieve this information from anywhere using yourKey:

let yourInstance = NSUserDefaults.standardUserDefaults().objectForKey("yourKey")


And you can specify its type according to your needs.

For more information, read the Apple Document for NSUserDefaults .

Another way to pass value from one view to another view without segue using Class

or Struct


More about Classes

and Structures

you can learn from Apple Documentation .



If our inputs are finite, create a model class with properties for ex:

@interface UserDataInput : NSObject
@property (nonatomic)NSString *name;
@property (nonatomic)NSString *contactNumber;
blah blah bla


then make it as a singleton class

@implementation UserDataInput
+ (instancetype)sharedInstance {
    static dispatch_once_t onceToken;
    static UserDataInput *sharedInstance = nil;
    dispatch_once(&onceToken, ^{
        sharedInstance = [[[self class] alloc] init];
    return sharedInstance;


Then set properties from the view controller when exiting that view controller, for example

UserDataInput *sharedInput = [UserDataInput sharedInstance]; = self.nameField.text;


In the target view controller, you can access these loading properties for parsing.



Try it.

let yourInstance = NSUserDefaults.standardUserDefaults().objectForKey("yourKey")




All Articles