Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 10-25-2010, 08:23 AM   #1 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 28
KyleTomson is on a distinguished road
Default Mutable arrays

I thought I would run this by everybody, it is driving me nuts. This shouldn't be so hard, but I feel like I'm missing something simple: Here is my code:

//temp array to hold file paths
NSMutableArray *slideShowFilesTemp = [NSMutableArray arrayWithCapacity:200];

// (I have tried to initialize slideShowFilesTemp this way too)
//NSMutableArray *slideShowFilesTemp;
//slideShowFilesTemp = [[NSMutableArray alloc] init];

//Audioclip file name
NSString *recorderFilePath;
recorderFilePath = [[NSString stringWithFormat:@"%@/%@.caf", DOCUMENTS_FOLDER, questionCorrectAnswerAudioFileName] retain];

//get image path
NSString *imageSelectionName;
imageSelectionName = [sentenceArray objectAtIndex:imageLocationPointer];
NSBundle *bundle3 = [NSBundle mainBundle];
NSString *imagePath1 = [bundle3 pathForResource@"%@", imageSelectionName) ofType:@"png"];

[slideShowFilesTemp addObject:recorderFilePath];
[slideShowFilesTemp addObject:imagePath1];

[self.slideShowFiles addObjectsFromArray:slideShowFilesTemp];

slideShowFiles is a mutable array and has accessor methods. What I am trying to do is keep track of the recorded filepath and the associated image and put them into a MutableArray for access later. This code is in a -IBAction routine that is run when you hit a button.

If I look at what goes into slideShowFilesTemp, it is exactly as I want it. However, when I do a NSLog of the slideShowFiles Mutable array, it comes back as a nil.

If I use the following code: "self.slideShowFiles = slideShowFilesTemp;", then slideShowFiles has exactly the same objects as slideShowFilesTemp, however it just overwrites whatever was in slideShowFiles (as I would expect). I want to add what it in slideShowFilesTemp to the back of slideShowFiles.

Am I not initializing slideShowFilesTemp correctly? I have tried it two ways as shown above. Any suggestions or pointers would be appreciated.

Kyle
KyleTomson is offline   Reply With Quote
Old 10-25-2010, 09:37 AM   #2 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

Where do you set slideShowFiles? If slideShowFiles is nil then this line:

Code:
[self.slideShowFiles addObjectsFromArray:slideShowFilesTemp];
is the same as calling
Code:
[nil addObjectsFromArray:slideShowFilesTemp];
Which has no effect. I'm guessing that you need to set slideshowfiles somewhere, like
Code:
self.slideShowFiles = [NSMutableArray array];
__________________

Free Games!
smasher is offline   Reply With Quote
Old 10-25-2010, 11:49 AM   #3 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 28
KyleTomson is on a distinguished road
Default mutable arrays

Quote:
Originally Posted by smasher View Post
Where do you set slideShowFiles? If slideShowFiles is nil then this line:

Code:
[self.slideShowFiles addObjectsFromArray:slideShowFilesTemp];
is the same as calling
Code:
[nil addObjectsFromArray:slideShowFilesTemp];
Which has no effect. I'm guessing that you need to set slideshowfiles somewhere, like
Code:
self.slideShowFiles = [NSMutableArray array];
I set slideShowArrays in the .h file. I declare it as a NSMutable array and set its property and then synethisize it in the .m file. All pretty standard stuff. I didn't think I would have to set it as a NSMutableArray again. I will give it a try.

This may seem like a dumb question, but if I declare slideShowFiles in my .h file and then synthesize accessor methods, why do I have to set it again?

Just trying to understand what is going on. I really appreciate the help!!
KyleTomson is offline   Reply With Quote
Old 10-25-2010, 12:28 PM   #4 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 327
thomashw is on a distinguished road
Default

Declaring it in your header file doesn't initialize it. Setting its property doesn't either. You need to allocate and initialize it in your code somewhere (in your init methods).

Just to give it a quick try, you could put this at the top of your code:

Code:
if( slideShowFiles == nil )
  slideShowFiles = [[NSMutableArray alloc] init];
thomashw is offline   Reply With Quote
Old 10-25-2010, 02:26 PM   #5 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 28
KyleTomson is on a distinguished road
Default

Quote:
Originally Posted by thomashw View Post
Declaring it in your header file doesn't initialize it. Setting its property doesn't either. You need to allocate and initialize it in your code somewhere (in your init methods).

Just to give it a quick try, you could put this at the top of your code:

Code:
if( slideShowFiles == nil )
  slideShowFiles = [[NSMutableArray alloc] init];
Thanks. I'll give that a try tonight and post back.
KyleTomson is offline   Reply With Quote
Old 10-25-2010, 11:49 PM   #6 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 28
KyleTomson is on a distinguished road
Default

Quote:
Originally Posted by KyleTomson View Post
Thanks. I'll give that a try tonight and post back.
Worked like a champ. Thanks for the help.
KyleTomson is offline   Reply With Quote
Old 10-26-2010, 12:44 AM   #7 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 327
thomashw is on a distinguished road
Default

Quote:
Originally Posted by KyleTomson View Post
Worked like a champ. Thanks for the help.
No problem. But make sure you're doing the initializing in your init methods. You don't want to have uninitialized instance variables after an instance of the class has been initialized.
thomashw is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 325
12 members and 313 guests
7twenty7, chiataytuday, condor304, Desert Diva, Domele, dre, dreamdash3, mottdog, palme2elie, Paul Slocum, schmallegory
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,659
Threads: 94,118
Posts: 402,895
Top Poster: BrianSlick (7,990)
Welcome to our newest member, dreamdash3
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:16 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0