Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jul 18, 2010, 12:22 PM   #1
CeiJay
macrumors newbie
 
Join Date: Jul 2010
NSMutableArray Question

How would one use this Array...

Code:
if (filmMovie == nil)
    {
        NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:
                                 @"Mov1.mp4", 
								 @"Mov2.mp4", 
								 @"Mov1.mp4", 
								 @"Mov2.mp4", 
								 @"Mov1.mp4", 
								 @"Mov2.mp4", 
                                 @"Mov1.mp4", 
								 @"Mov2.mp4", 
								 @"Mov1.mp4", 
								 @"Mov2.mp4", nil];
        self.filmMovie = array;
        [array release];        
    }
to populate this...

Code:
NSString *path = [[NSBundle mainBundle] pathForResource:@"INFO FROM ARRAY" ofType:@"mp4"];
or

Code:
NSString *path = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"INFO FROM ARRAY"];
CeiJay is offline   0 Reply With Quote
Old Jul 18, 2010, 12:59 PM   #2
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Are you trying to figure out how to reference a single element/object from the array using, say, an index number?
__________________
dejo is offline   0 Reply With Quote
Old Jul 18, 2010, 01:04 PM   #3
CeiJay
Thread Starter
macrumors newbie
 
Join Date: Jul 2010
Quote:
Originally Posted by dejo View Post
Are you trying to figure out how to reference a single element/object from the array using, say, an index number?
Hi Again Dejo

I managed to get the following to load an audio file from an Array without a problem.

Code:
NSUInteger row = [indexPath row];
    NSString *rowTitle = [filmSound objectAtIndex:row];

NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@", [[NSBundle mainBundle] resourcePath], rowTitle]];
	NSError *error;
	AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
yet with this...

Code:
NSString *path = [[NSBundle mainBundle] pathForResource:@"INFO FROM ARRAY" ofType:@"mp4"];
or this...

Code:
NSString *path = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"INFO FROM ARRAY"];
I am unable to do the exact same thing. Using the Audio example does not work as NSString*path is required.
CeiJay is offline   0 Reply With Quote
Old Jul 18, 2010, 01:40 PM   #4
chown33
macrumors 603
 
Join Date: Aug 2009
Show real code. The literal string @"INFO FROM ARRAY" can't possibly work.

Also, pathForResource expects resource names to NOT have an extension if the ofType parameter is non-nil. Your array of strings DOES have ".mp4" extensions on every string. So either remove the extensions from the array strings, or pass nil instead of "mp4". Refer to the NSBundle reference doc, in the section on pathForResource methods.
chown33 is offline   0 Reply With Quote
Old Jul 18, 2010, 01:48 PM   #5
CeiJay
Thread Starter
macrumors newbie
 
Join Date: Jul 2010
Quote:
Originally Posted by chown33 View Post
Show real code. The literal string @"INFO FROM ARRAY" can't possibly work.

Also, pathForResource expects resource names to NOT have an extension if the ofType parameter is non-nil. Your array of strings DOES have ".mp4" extensions on every string. So either remove the extensions from the array strings, or pass nil instead of "mp4". Refer to the NSBundle reference doc, in the section on pathForResource methods.
Hi Chown

Thank you for your input. I am happy with the inType and removing from the Array and the Nil pass. Refined Question.

NSString *path = [[NSBundle mainBundle] pathForResource:@"%@" ofType:@"mp4"];

%@ need to be whatever is in the Array. One example that seems not to work because it changes NSString *path to NSURL *path.

NSURL *path = [NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource:rowTitle ofType:nil]];

--

How to load info from the Array into here... making sure to keep using NSString *path =

NSString *path = [[NSBundle mainBundle] pathForResource:@"%@" ofType:@"mp4"];

Thoughts?
CeiJay is offline   0 Reply With Quote
Old Jul 18, 2010, 02:45 PM   #6
chown33
macrumors 603
 
Join Date: Aug 2009
Quote:
Originally Posted by CeiJay View Post
NSString *path = [[NSBundle mainBundle] pathForResource:@"%@" ofType:@"mp4"];

%@ need to be whatever is in the Array. One example that seems not to work because it changes NSString *path to NSURL *path.

NSURL *path = [NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource:rowTitle ofType:nil]];

--

How to load info from the Array into here... making sure to keep using NSString *path =

NSString *path = [[NSBundle mainBundle] pathForResource:@"%@" ofType:@"mp4"];

Thoughts?
If that's your actual code, it can't possibly work. You can't just throw in a formatting string @"%@" for any method. Only a small number of methods accept formatting strings. pathForResource is not one of them.

You've already posted code that retrieves an indexed string from the array. It's this:
Code:
NSUInteger row = [indexPath row];
    NSString *rowTitle = [filmSound objectAtIndex:row];
If you can't figure out how to proceed, then you should think about what's in the string rowTitle, and how that relates to the pathForResource string. If it's still not clear, you need to go back and review the basics.

You should also take a little time and mentally step through what value is in each variable. Use a pencil and paper if you can't keep it all in your head. If you don't understand what values are in which variables, and how those values relate to what you're trying to do, you can't possibly write code effectively. You need to think it through and understand the code.
chown33 is offline   0 Reply With Quote
Old Jul 18, 2010, 02:48 PM   #7
CeiJay
Thread Starter
macrumors newbie
 
Join Date: Jul 2010
Thank you for all you help Chown - I will work on it...
CeiJay is offline   0 Reply With Quote
Old Jul 18, 2010, 06:37 PM   #8
CeiJay
Thread Starter
macrumors newbie
 
Join Date: Jul 2010
Quote:
Originally Posted by chown33 View Post
If that's your actual code, it can't possibly work. You can't just throw in a formatting string @"%@" for any method. Only a small number of methods accept formatting strings. pathForResource is not one of them.

You've already posted code that retrieves an indexed string from the array. It's this:
Code:
NSUInteger row = [indexPath row];
    NSString *rowTitle = [filmSound objectAtIndex:row];
If you can't figure out how to proceed, then you should think about what's in the string rowTitle, and how that relates to the pathForResource string. If it's still not clear, you need to go back and review the basics.

You should also take a little time and mentally step through what value is in each variable. Use a pencil and paper if you can't keep it all in your head. If you don't understand what values are in which variables, and how those values relate to what you're trying to do, you can't possibly write code effectively. You need to think it through and understand the code.
Thank you for your help.

The solution was the following...

Code:
NSInteger row = indexPath.row;
	NSString *rowTitle = [filmMovie objectAtIndex:row];

		NSString *path = [[NSBundle mainBundle] pathForResource:rowTitle ofType:nil];
CeiJay is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
nsmutablearray tacotester1 iPhone/iPad Programming 6 Apr 10, 2014 04:18 PM
NSMutableArray always replacing last value. DavidBlack Mac Programming 16 Dec 15, 2013 03:49 PM
NSMutableArray only adds one object! Oneill iPhone/iPad Programming 5 Oct 23, 2013 05:42 PM
Objective-C help with NSMutableArray dancks Mac Programming 4 Apr 15, 2013 04:25 PM
NSArray to NSMutableArray larswik Mac Programming 3 Feb 19, 2013 10:10 PM

Forum Jump

All times are GMT -5. The time now is 02:12 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC