nsmutablearray addobject adding object.text twice [closed] - ios

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
Using addObject is adding the object twice
AppDelegate *appdelegate = [[UIApplication sharedApplication] delegate];
NSLog(#"LOG1 %#", object.text);
[appdelegate.mutarray addObject:object.text];
NSLog(#"LOG2 %#", appdelegate.mutarray);
Log1 returns: LOG1 value
Log2 returns: LOG2 (
"value",
"value"
)
why is it adding in twice? removeObject removes both can i remove just one

Because your first time added your value to NSMutableArray through without remove value from the NSMutableArray going add often. that so far it be adding concurrent duplicate value. before adding new value remove your entire array.
if(appdelegate.mutarray.count!=0)
[appdelegate.mutarray removeAllObject];
[appdelegate.mutarray addObject:object.text];

Related

What is the best way to use if([names count]>1) in swift? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
In Objective C we used
if([names count]>1){
// array count is greater than one
}
The same way i tried to check in swift. But the complier shouts.
Any idea??
The correct way to write it should be:
if name.count > 1 {
// Your code here
}
Your syntax is incorrect. Brackets are used in Objective-C, not Swift.
Try this:
var shoppingList = ["Eggs", "Milk"]
if(1 < shoppingList.count) {
println( "Greater than one")
}

save string variable in NSMutableArray -Error [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm new to iOS and its development. Here I'm passing string value to saveStringpath variable then I want to save it in type NSMutable array saveStrings but I'm getting:
thread 1 exc_bad_access (code=2 type breakspoint
please help me.
//here i need to save these data in NSMutable array
-(void)saveNSMutablearray:(NSString*)saveStringpath
{
//start Mutable array to save this values
NSMutableArray *saveStrings =[[NSMutableArray alloc]init];
[saveStrings addObject:saveStrings];
NSString *test = [saveStrings objectAtIndex:0];
NSLog(#"JSON:-----vm %#", test);
}
The problem you are facing is because of wrong variable name. In your code you are adding array into array, so to solve the problem please change this line:
[saveStrings addObject:saveStrings];
into that one:
[saveStrings addObject:saveStringpath];
and the problem is gone :)

Compare Placeholder Text in text field [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I have set the placeholder text(e.g. Under 18s) of a text field(homeTeam) in storyboard. Now i want to check the condition something like below.
- (BOOL)textFieldShouldBeginEditing:(UITextField *) textField
{
if ([_homeTeam.text isEqualToString:#"e.g. Under 18s"]) { // e.g. Under18s
[_homeTeam setPlaceholder:#""];
}
}
But the condition is never getting true. What am i missing here? _homeTeam.text is blank when i used NSlog to trace. Why is it so?
Please suggest.
change your if condition, it should be _homeTeam.placeholder not _homeTeam.text because you set placeholder text not a text of UITextField.
- (BOOL)textFieldShouldBeginEditing:(UITextField *) textField
{
if ([_homeTeam.placeholder isEqualToString:#"e.g. Under 18s"]) { // e.g. Under18s
[_homeTeam setPlaceholder:#""];
}
}
You actually want to compare against the placeholder property, not text (which is input by the user).
Also, I would instead refer to textField (instead of _homeTeam directly, as you might add other text fields later), as such:
- (BOOL)textFieldShouldBeginEditing:(UITextField *) textField
{
if ([textField.placeholder isEqualToString:#"e.g. Under 18s"]) { // e.g. Under18s
[textField setPlaceholder:#""];
}
}

Get latest inserted object FatFractal [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I'm using FatFractal for my backend in a iPhone-app. Been searching the web and FatFractal docs without any luck.
I want to retrieve the latest object in a collection from a grabbag:
NSArray *result = [[Store ff] grabBagGetAllForObj:thread grabBagName:#"messages" withQuery:#"Get the latest inserted object" error:&err];
Probably the best way to do this is to construct the full query yourself and then use the standard getArrayFromUri: method. Taking your example, this would look like:
FatFractal *ff = [Store ff];
NSString *query = [NSString stringWithFormat:
#"%#/messages?sort=createdAt desc&start=0&count=1",
[ff metaDataForObj:thread].ffUrl];
NSArray *result = [ff getArrayFromUri:query];
For more info, see http://fatfractal.com/prod/docs/queries/#sorting-and-limiting-results.

UIPickerView under empty selection [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
When my UIPickerView View is empty [the array is loads the data from is empty], If I try to select the Picker View the application crashes. What is the solution
I'm not sure but i guess that error generated because your array is empty and you should write any where in delegate method of UIPickerView such like [array objectAtindex....]; so,,
In each statement which you write [array objectAtindex....]; put condition that
if(array.count > 0)
[array objectAtindex....];..
So your picker will open but not generate any error.
EDITED:
I got solution for you:
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
if ([myArray count] == 0)
return 1;
return [myArray count];
}
No need to apply any other condition i was checked it, in my project.
It's due to array out of bound exception it seems.
Check whether you are using any static index value while selecting the values.
e.g [sourceArray objectAtIndex:0]; // It get crash when the source array is empty.

Resources