save string variable in NSMutableArray -Error [closed] - ios

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 :)

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")
}

SWIFT: Why I can't get the current URL loaded in UIWebView? [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 need to get the current URL loaded into the webview and this is how I'm trying to get that but it gives me this error: "Cannot convert the exporessions type 'ST7??' to type 'String'
and this is the code
var currentURL : NSString = webView.request?.URL.absoluteString!
What is wrong with this?
If you put parentheses around this, the error goes away:
let currentURL : NSString = (webView.request?.URL.absoluteString)!
Beware that yours might not be just a syntax problem.
If your webView is in a state where request == nil your app will crash at runtime.
I'd rather write something like:
if let currentURL = webView.request?.URL.absoluteString {
// do things ...
// Your currentURL will be automatically bridged to Swift's String type
} else {
// Just in case request is nil ...
}

nsmutablearray addobject adding object.text twice [closed]

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

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