I'm new to iOS programming and am creating an app with several viewControllers. One of the viewControllers is a settings tab and I'd like to store a few variables so that I can use it across the controllers. Is there a standard way of doing this? I'm currently looking into NSUserDefaults but any design patterns out there would be appreciated.
            Asked
            
        
        
            Active
            
        
            Viewed 49 times
        
    -1
            
            
         
    
    
        locoboy
        
- 38,002
- 70
- 184
- 260
- 
                    I don't simply want to pass information - i also want to store it. – locoboy Oct 27 '13 at 15:55
- 
                    CoreData is also an option and I personally think its a must know especially if you find yourself needing to store structured data. Plus, it's a very elegant solution to data storage and handling once you get the hang of it. – Jonathan Nov 03 '13 at 17:06
2 Answers
0
            
            
        1. With Storyboards -
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{
    if ([segue.identifier isEqualToString:@"xyzView"]) 
    {
        MyViewController *destViewController = segue.destinationViewController;
        destViewController.objectPassedFromPrevViewController = dataToBePassedToNextViewController
    }
}
2. With Navigation Controller -
DestinationViewController *destinationController = [[DestinationViewController alloc] init];
destinationController.objectPassedFromPrevViewController = dataToBePassedToNextViewController;
[self.navigationController pushViewController:destinationController animated:YES];
3. While Adding Subview -
DestinationViewController *destinationController = [[DestinationViewController alloc] init];
destinationController.objectPassedFromPrevViewController = dataToBePassedToNextViewController;
[self.view addSubview:destinationController.view];
 
    
    
        Aditya Deshmane
        
- 4,676
- 2
- 29
- 35
0
            
            
        Your inclination to use NSUserDefaults is a good one. Its made for storing and retrieving user settings and preferences for your app.
 
    
    
        Jonathan Arbogast
        
- 9,620
- 4
- 35
- 47