0

I have a UITextField called txtvwEmail. i am adding the text from txtvwEmail.text to the Array pastUrls but after adding the next text it remove the first text. Im using the code

if (![pastUrls containsObject:txtvwEmail.text]) {
    [pastUrls addObject:txtvwEmail.text];
}
6
  • Can you elaborate more on what you were trying to do / expecting? Commented Aug 2, 2011 at 14:48
  • addObject will increase the retain count. What kind of object is txtvwEmail.text? Commented Aug 2, 2011 at 14:48
  • i am adding the text from txtvwEmail.text in the Array pastUrls but after adding the next text it remove the first text Commented Aug 2, 2011 at 14:49
  • 1
    Have you tried casting txtvwEMail.text to an local NSString variable (ie, NSString* emailString = [NSString stringWithFormat:@"%@", txtvwEmail.text]) and then [pastUrls addObject:emailString];? stringWithFormat is an autoreleased helper, so there shouldn't be any issues with memory leaks there. Commented Aug 2, 2011 at 15:03
  • What count? You mean the number of objects in the array? How are you determining the count? [array count]? Commented Aug 2, 2011 at 15:18

2 Answers 2

2

You should rely on the basics of the language and frameworks. The array DOES RETAIN the object, however, it could be:

  1. pastUrls is nil -> no retain
  2. somewhere in the code .text is released (or autoreleased) and the count is yet the same

Also, you can't really be sure [obj retainCount] return the correct value. To diagnose the real problem, revise the code or post it here so we can help.

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

Comments

1
//this should be outside of ur all loops
NSMutableArray *pastUrls=[[NSMutableArray alloc]init];

//remove this line
//NSMutableArray *pastUrls=[NSMutableArray array];

if (![pastUrls containsObject:txtvwEmail.text]) {
    [pastUrls addObject:txtvwEmail.text];
}

NSLog(@"pastUrls : %@ \n\n",pastUrls);

Comments

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.