Rausi
Rausi

Reputation: 1

Adding Strings in NSMutableArray

I am in my IOS application in which i am getting ID from server which i am saving in string and then add strings in NSMutableArray.I am not getting perfect method by which i can add the strings in array and use the array outside the scope. Here is my code Please help me out::

- (void)flickrAPIRequest:(OFFlickrAPIRequest *)inRequest didCompleteWithResponse:(NSDictionary *)inResponseDictionary
{
NSMutableArray *array=[[NSMutableArray alloc]init];
    i=0;
    NSLog(@"%s %@ %@", __PRETTY_FUNCTION__, inRequest.sessionInfo, inResponseDictionary);
    if (inRequest.sessionInfo == kUploadImageStep)
    {
        snapPictureDescriptionLabel.text = @"Setting properties...";
        NSLog(@"%@", inResponseDictionary);

     NSString* photoID =[[inResponseDictionary valueForKeyPath:@"photoid"] textContent];
     flickrRequest.sessionInfo = kSetImagePropertiesStep;

// for uploading pics on flickr we call this method
  [flickrRequest callAPIMethodWithPOST:@"flickr.photos.setMeta" arguments:[NSDictionary dictionaryWithObjectsAndKeys:photoID, @"photo_id", @"PicBackMan", @"title", @"Uploaded from my iPhone/iPod Touch", @"description", nil]];
   [self.array addObject:photoID];
    arr=array[0];
    counterflicker++;
     NSLog(@"  Count : %lu", (unsigned long)[array count]);

}

How can i add the photoID(Strings) in the array? Please help me out..

Upvotes: 0

Views: 119

Answers (3)

Deepika
Deepika

Reputation: 263

for adding NSString in NSMutableArray is like this

NSString *str = @"object";
NSMutableArray *loArr = [[NSMutableArray alloc] init];
[loArr addObject:str];

In your code Why are you using self.array ? just write like this. [array addObject:photoID];

Upvotes: 1

Dipen Chudasama
Dipen Chudasama

Reputation: 3093

I observe that in your code. you declare mutable array in local scope.

So just use

 [array addObject:photoID];

Instead of 

   [self.array addObject:photoID];

May be you are create property for this array with same name, then you need to alloc it.

If you create a property for this then remove local declaration and alloc array like this.

 self.array=[[NSMutableArray alloc]init];

and then use

   [self.array addObject:photoID];

Upvotes: 0

Jayaprada
Jayaprada

Reputation: 954

  • self keyword is used for global variables but here in your code "array" is a local variable .So need of self.array

[array addObject:photoID];

  • Before adding check that photoID is nil or not
 if (photoID.length > 0) {
        [array addObject:photoID];
    }

Upvotes: 0

Related Questions