0

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..

7
  • 3
    What precisely is the problem? Commented Apr 24, 2014 at 12:31
  • Why are you use self.array ? Only write like this. [array addObject:photoID]; Commented Apr 24, 2014 at 12:32
  • if you want to use the array in a parent scope, probably you have to define the array in the parent scope. does is make sense to you? Commented Apr 24, 2014 at 12:33
  • are you sure you got a photoID ? Commented Apr 24, 2014 at 12:50
  • yes i am getting photoID,but when i am adding the strings in array,every time it adds object but all objects contains same value. Commented Apr 24, 2014 at 13:02

3 Answers 3

1

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];

Sign up to request clarification or add additional context in comments.

2 Comments

why are you copy my answer ?
i am not copy ur ans . see my ans carefully. please
0
  • 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];
    }

Comments

0

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];

1 Comment

I am already making property for this array,and also declare this in .h file,,but i am unable to add strings in the array?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.