-3

I've looked at other posts and none of them make any sense. I have an AppController (for a NSCollectionView), and I have a table in it called filePaths. File paths is an @property. MY object file (for the collection view), needs those paths. How do I transfer the filePaths from AppController to my file class? Singletons and other things are confusing to me, even though I've read a lot about them. If you have an answer involving singletons or something similar, please explain it, because I have no idea what is going on.

Minebomber
  • 1,209
  • 2
  • 12
  • 35

2 Answers2

0

Simply assign it to a property.

Amin Negm-Awad
  • 16,582
  • 3
  • 35
  • 50
0

If you're using storyboards, you'll want to use the "prepare for segue" method typically found at the bottom of your view controllers.

You'll create a property in the destination view controller like this in your header:

@property (nonatomic) NSMutableArray *recievedArray;

and in your origin view controller's m file (the m file where the mutable array originally is) you'll import the destination view controller at the top like so

#import "DestinationViewController.h"

Now we'll populate "prepareForSegue" :

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
      if ([[segue identifier] isEqualToString:@"segueToDestinationViewController"]) {

           DestinationViewController *vc = [segue destinationViewController];
           [vc setRecievedArray:theMutableArray];
      }
}

Where "segueToDestinationViewController is what you set in storyboard like this (I reused this image from something else but you want to click on the segue arrow and fill in "Identifier" with "segueToDestinationViewController")enter image description here

Now you're all set and the property will be properly assigned upon segue!

Edit: You can also set up singletons easily by creating your singleton class and adding this method to it:

+ (id)sharedManager {
static MyManager *sharedMyManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
    sharedMyManager = [[self alloc] init];
});
return sharedMyManager;

Then you will invoke the single instance of the singleton using the class method like this

MyManager *mySingleton = [MyManager sharedManager];

Going through the GCD like this is pretty fool proof so you should be fine. Now all you have to do is get the properties from the singleton instance.

Cole
  • 2,641
  • 1
  • 16
  • 34