-1

I am using multiple iCarousels and want to import pictures from the directory. I have iCarousel 1 on top and have iCarousel 2 on the bottom. I have about 6 folders in the directory in the iOS device where the user has taken pictures. I want to assign the iCarousel 1 to directory "apple" and iCarousel 2 to directory "green".

The below is my code until now. However of course, this gets an error saying "Redefinition of..." since I am setting paths for 2 imageArrays. How should I make this code simpler?

Furthermore, I also have a warning saying 'NSMutableArray *_strong' from 'NSArray *_strong' at the imageArray2 = directoryContent; line. I really want to make this all working.

- (void)viewDidLoad
{
    [super viewDidLoad];

    //configure carousel
    imageArray1 = (NSMutableArray *)[[NSFileManagerdefaultManager] directoryContentsAtPath: fPath];
    NSString *location=@"apple";
    NSString *fPath = [documentsDirectory stringByAppendingPathComponent:location];
    NSArray *directoryContent = [[NSFileManager defaultManager] directoryContentsAtPath: fPath];
    imageArray1 = directoryContent;

    imageArray2 = [[NSMutableArray alloc] init];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *location=@"green";
    NSString *fPath = [documentsDirectory stringByAppendingPathComponent:location];

    NSArray * directoryContent = [[NSFileManager defaultManager] directoryContentsAtPath: fPath];
    imageArray2 = directoryContent;

    carousel1.type = iCarouselTypeLinear;
    carousel2.type = iCarouselTypeLinear;
}
Dennis Meng
  • 5,109
  • 14
  • 33
  • 36
poradi
  • 23
  • 2

1 Answers1

0

You're declaring some variables twice.

you can do something like this:

-(void)viewDidLoad
{
   [super viewDidLoad];

   //configure carousel
   imageArray1 = (NSMutableArray *)[[NSFileManager defaultManager] directoryContentsAtPath: fPath];
   NSString *location=@"apple";
   NSString *fPath = [documentsDirectory stringByAppendingPathComponent:location];
   NSArray *directoryContent = [[NSFileManager defaultManager] directoryContentsAtPath: fPath];
   imageArray1 = [directoryContent mutableCopy];

   imageArray2 = [[NSMutableArray alloc] init];
   NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
   NSString *documentsDirectory = [paths objectAtIndex:0];
   location=@"green";
   fPath = [documentsDirectory stringByAppendingPathComponent:location];

   directoryContent = [[NSFileManager defaultManager] directoryContentsAtPath: fPath];
   imageArray2 = [directoryContent mutableCopy];

   carousel1.type = iCarouselTypeLinear;
   carousel2.type = iCarouselTypeLinear;
}
Joshua
  • 2,432
  • 1
  • 20
  • 29
  • Thanks and one more thing.. I am getting an error that is saying Use of undeclared identifier 'NSFileManagerdefaultManager' and Use of undeclared identifier 'documentsDirectory'; did you mean 'NSDocumentDirectory'? and Bad receiver type 'NSUInteger' (aka 'unsigned int'). What do you think is wrong? – poradi Aug 29 '13 at 07:41
  • 1
    Dude you better read the API in the Apple developer's site. We can't spoon feed everything to you. – Joshua Aug 29 '13 at 10:42