NSURL Exceptions - iphone

I am trying to grab a path value from an array for an NSURL to set an icon in my app. I get an
NSInvalidArgumentException', reason: '-[__NSArrayI length]: unrecognized selector sent to instance 0x5622590.
If I use an nslog I get the expected output:
NSLog(#"%#",[[wforecast.wicons objectAtIndex:0]valueForKey:#"nodeContent"]);
Which gives me:
Im setting the value as follows
NSURL *urlpath;
NSString *urls = [[wforecast.wicons objectAtIndex:0] valueForKey:#"nodeContent"];
urlpath = [NSURL URLWithString:(NSString *)urls];
I appreciate this is a longwinded way of doing things but I was trying to break up the individual components to find out what was going wrong but I am at a loss!

You have essentially the same problem as this other questioner had. You passed an object that is not an NSString where you needed to pass an NSString.
Use the debugger to determine exactly where the exception occurred. If you haven't done this, I wouldn't be so sure that the code you showed is what caused it; the debugger will tell you where the exception occurred with no room for doubt.
Once you've found where the exception occurred, you can examine the object that you passed, and look back at where you got it from. You need to fix either how you retrieve the string or how you stored it in the place you're now getting it from.

Related

Passing UISearchBar.text to another function

It's my first time working with a UISearchBar and so far it went fine, but now after clicking "search" I'm trying to pass the text to another function that handles the search.
[_searchModel searchIssueForTerm:searchBar.text inIssue:_dataModel.currentIssue];
This just throws me an error, saying:
-[CFString copyWithZone:]: message sent to deallocated instance 0x7dee900
But when I use this, it just works
[_searchModel searchIssueForTerm:#"test" inIssue:_dataModel.currentIssue];
Why is this hapenning? In my - (void)searchIssueForTerm:(NSString *)searchTerm inIssue:(Issue *)issue I store the NSString in another variable, why would it get deallocated then?
After searching for a while I managed to fix it by just saving the variable somewhere else, seems it was getting lost along the way.
_currentSearchTerm = [[NSString alloc] initWithString:searchTerm];

how can i query google places for country specific cuisine?

i am trying to accomplish country specific Cuisine places, means like mexican food, spanish food, Thai food, indian food, via google places API on an iPhone app.
How can i do that?? As i see supported types, there is only food, restaurant, etc in it. besides whenever i use this query..
NSString *url = [NSString stringWithFormat:#"https://maps.googleapis.com/maps/api/place/search/json?location=%f,%f&radius=%#&type=restaurant&query=%#&sensor=true&key=%#", currentCentre.latitude, currentCentre.longitude, [NSString stringWithFormat:#"%i", currenDist], googleType, kGOOGLE_API_KEY];
i am getting few results only, whenever i try to add more types like food|restaurant|establishment like below query my app crashes.
NSString *url = [NSString stringWithFormat:#"https://maps.googleapis.com/maps/api/place/search/json?location=%f,%f&radius=%#&type=food|restaurant|establishment&query=%#&sensor=true&key=%#", currentCentre.latitude, currentCentre.longitude, [NSString stringWithFormat:#"%i", currenDist], googleType, kGOOGLE_API_KEY];
As i told my app crashes with this error may be i am doing something wrong with url.
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'data parameter is nil'
* First throw call stack: (0x13be022 0x200fcd6 0x1366a48 0x13669b9 0xbadfad 0x2dd2 0x13bfe42 0xaa09df 0x139294f 0x12f5b43 0x12f5424
0x12f4d84 0x12f4c9b 0x15d47d8 0x15d488a 0x17a626 0x236d 0x22d5)
terminate called throwing an exception(lldb)
Please can someone guide me with this?? i hope i cleared all my points.
Thanks & regards,
Malhaar
It appears you are trying to use the Places API Textsearch as you are using the query parameter. If this is correct make sure you are hitting the correct backend:
maps.googleapis.com/maps/api/place/textsearch/json
Also make sure you are using the correct parameter to specify types:
types=food|restaurant|establishment
I would recommend reading the documentation thoroughly and and performing a few test html requests through your browser to make sure you have the right request before plugging it into your application.
Although this is almost 7 months old, and I'm sure you've either solved it or given up on it by now, I have just had the same issue and it took some resolving. I thought I'd put the answer here to help anyone else with a similar error.
The problem I found was to do with the URL encoding not liking the | character.
The way around it I found was to:
// Create an NSString with the URL which includes the '|' characters.
NSString * urlString = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=51.189781,-114.488907&radius=6918&types=food|bar&keyword=&sensor=true&key=YOUR KEY HERE";
// Encode the URL
NSString* encodedURLString = [urlString stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
// Covert to a NSURL
NSURL *googleRequestURL=[NSURL URLWithString:encodedURLString];
And then use the googleRequestURL as the URL.
Hopefully that will solve it for you!

Exception throwing JSON supporting program in iphone

I downloaded JSON files. I added these files in project directory. But when I am runnig program I am getting an error which is...
-[__NSCFDictionary
JSONRepresentation]: unrecognized
selector sent to instance 0x6003d50
* Terminating app due to uncaught exception
'NSInvalidArgumentException', reason:
'-[__NSCFDictionary
JSONRepresentation]: unrecognized
selector sent to instance 0x6003d50'
* Call stack at first throw:
I imported header file #import "JSON/JSON.h" and I wrote jsocn code in viewDidLoad function which is like below...
NSDictionary *requestData = [NSDictionary dictionaryWithObjectsAndKeys:
#"grio", #"username",
#"hellogrio", #"password",
nil];
NSString* jsonString = [requestData JSONRepresentation];
NSLog(#"%#", jsonString);
Kindly help me.
Thanks in advance.
I am guessing you are using json-framework. You probably forgot to add -all_load to the linker flags. See this question for more details.
It's not clear from your question which JSON implementation you're using, but the error means that you're sending the JSONRepresentation message to an NSDictionary. The dictionary does not understand the message and raises an exception.
It seems that either you're not using the JSON library correctly or that you have not installed it correctly in your project.

trying to obtain an objects title variable gives unrecognized selector sent to instance

I have an object which holds a title and an indexReference. I save the object to an array and that works correctly.
I then try to load from the array and populate the tableview.
I use this code.
//fill it with contents
SavedFav *temp = [tableViewData objectAtIndex:indexPath.row];
cell.textLabel.text = temp.title;
I then get an error as the following
2010-07-01 15:42:46.386 Daily Quote[1308:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString title]: unrecognized selector sent to instance 0x23f6688'
What is causing this problem?
Thanks in advance.
"temp" is a string obviously, so it's too many answers to give, either you filled tableViewData with strings and trying to obtain title from a string (which is unrecognized) or you have problem with memory there, without seeing more code it's hard to say.
however try
cell.textLabel.text = temp;
and check what's inside, that will give you a good lead.

AVAudioPlayer initialization: error code -50

I recently ran into a problem that I couldn't find discussed anywhere on the internet - I was initializing an AVAudioPlayer to play an audio file, and getting the following error:
Error Domain=NSOSStatusErrorDomain Code=-50 "Operation could not be completed. (OSStatus error -50.)
As it turns out, I had made a mistake creating my NSURL to send to the audio player init method, resulting in the NSURL object being null. Stupid mistake, pretty easy to find when debugging, but I thought I'd list it here just in case someone else does the same thing.
“ OSStatus error -50” means paramErr, an old-style Mac error code indicating a bad parameter.
Regarding the comment from Brynjar:
The Apple NSURL Class Reference describing URLWithString states
To create NSURL objects for file system paths, use
fileURLWithPath:isDirectory: instead.
I have found that using URLWithString for file system paths generates the error reported by pix0r and therefore could be another explanation for error code = -50
Make sure your NSURL is valid, or you will get error code -50 "Operation could not be completed".
I'm adding my version of the issue and solution because I encountered the error with a print statement. I think it was related to string interpolation and or trying to forcibly print nsattributedstrings. I attempted to do the following.
print("THE ARRAY COUNT IS : \(unwrappedResults.count)\n\n\n
THE FULL ARRAY IS THE FIRST WHOLE RESULT IS: \(unwrappedResults)\n\n\n \ (unwrappedResults[0])\n
THE ATTRIBUTED FULL TEXT IS: \(unwrappedResults[0].attributedFullText)\n\n\n
THE ATTRIBUTED PRIMARY TEXT IS: \(unwrappedResults[0].attributedPrimaryText)\n\n\n
THE ATTRIBUTED SECONDARY TEXT IS: \(unwrappedResults[0].attributedSecondaryText)\n\n\n")
something about this was incorrect and no print would occur. I would receive the error following errors in my console.
boringssl_metrics_log_metric_block_invoke(131) Failed to log metrics
&
boringssl_metrics_log_metric_block_invoke(133) Error Domain=NSOSStatusErrorDomain Code=-50 "Unsupported xpc type"
UserInfo={NSDescription=Unsupported xpc type}
I fixed this issue by changing the way I unwrapped/the variables values. Fundamentally I think I was trying to print something using string interpolation that could not be printed and that is what caused this error.