Yelp API displaying data - iphone

I've been looking up and down and there doesn't seem to be much documentation on this. I am just beginning development, and have no prior programming experience aside from HTML which doesn't really count.
I am able to successfully pull data with URL queries as I can see in my console. My question is, if I wanted to send a query for restaurant reviews, as an example, how do I get that data from the console to the iPhone view, right on the screen? If someone were able to provide a simple example I would appreciate it.

I'll give you the general steps:
1) Parse the JSON (which is probably an array of dictionaries) so loop through the array with an inner loop iterating the dictionaries. You could also use JSONKit.
2) Optionally cache the data somewhere (NOTE: If you use core data, there is a nice NSManagedObject method that will basically create an NSManagedObject directly from JSON).
3) Display it using UIKit (i.e. a Table view, where each cell displays the text and images your are retrieving).
If you need any specific help with any of those steps, please post new questions as you go along -- Break it down and tackle one problem at a time.
Also, if you use Core Data to persist this JSON data, you could use the NSFetchedResultsController as the datasource for your table view, which simplifies that some too.
I know you probably wanted me to write the code for you, but you've asked a very ambiguous question, whose scope is really too broad. If you follow those steps and have specific questions, we will help you work through it as you go.

Related

Populating Core Data with Plist in Swift

Working on an application that I want to check the plist store that the app will come shipped with and prepopulate core data with the objects from the plist. I think....I am looking for advice on this part of my application. As this is my first time coding and I have been learning Core Data/Persistence more recently I am not used to reading C++ or any of the code completely prior to Swift. I understand it somewhat but not enough to actually know the order of coding within swift.
That being said I created a plist file that contains an array of objects that each of those objects contains either strings or integers depending on the value that was necessary. Now in those objects I actually made a "serial" number as it were so that I could refer to specific objects easily or use it as a means to store that particular string and save only that so that it could be recalled from the plist. I have no idea whether I should actually upload all the objects to core data or just leave them in plist. Nor do I have any idea which way to begin this section of code.
From my basic understanding of plist and the fact that I saved the serial as a string I figured I could present the objects selected by storing the string alone to the core data model then have the core data model recall all objects from the plist that contain that serial and present it to the user. Basically any small sample coding in swift that can actually head me in the right direction would be a big help! Also is it faster to do it this way or would it be faster/better to upload the objects to core data on the first launch/updated lists? How would I go about this method if that was better? I spent the better half of the last few days trying to read through non swift code and haven't progressed enough I feel.
Sorry if this is n00bish I am self taught in swift and really trying to learn the best ways for all this as I have a lot of ideas that I wish to personally create/oversee!

Zend Table relations saving / updating

Currently I'm working on a cms page module where I need to update pages after made some modifications on for instance the text. Because I'm getting multiple data from several tables, I also need to save / update the data to multiple tables.
Updating data to one particular table isnt a problem, but for some reason I cant figure out how to do the same trick with table relationships. One of my questions is how to do this and if you maybe need to create a single savePage method for every model and handle the particular data seperately. Or is their a better solution to handle the saving with options like ManyToManyRowsets.
I'm not sure if its me searching for the wrong thing or if the thing I want, just doesnt excist. Anyway, the following link seems to look a little like what I want. If someone could help me out, I would be very thanksfull.
https://stackoverflow.com/a/640648/1553963
this post should answer your question (there is no easy way) and provide you with an how to too:
Zend Many to Many Relationship
Lucian

NSDictionaries and NSArrays from JSON from complicated YouTube API

I'm making an awesome iPhone app which searches for YouTube videos using the JSON API. However, Google is lazy so they just transformed the ATOM feed into JSON. Things look like this:
feed->entry[0]->author[0]->name->$t
This means that getting the information out of the NSArray is difficult, as I need to get a value of a key of an object of an array of an object of an array of an object of a key.
To check if the structure is correct, I can choose two things:
Use a huge amount of code for each item I want to check if the JSON was correct.
Wrap everything in a #try block.
I'd like to choose the second one. The problem is that some time ago I read that this is bad practice. Is it? And if so, is there a shorter way to validate the NSArrays en NSDictionaries? My app may never crash, not even if the user remover the processor at runtime, so not checking at all is not an option.
Can you please help me? Thanks.
Have you tried the GData API? I'm using it for my application ( http://itunes.apple.com/us/app/skystop/id392782307?mt=8 ) for the Youtube Feed. It basically spits out an XML file for whatever you've requested and you can convert it right into a plist file or an NSArray.
i'm not sure i understand, the API itself works in JSON instead of ATOM so you need to di into every item ?
If this is so then you are right, not much you can do except to seardch the web for helper libraries that might have been made even in google code to support this API.
In any case #2 is bad practice first of all since try catch usually consume more system resources then simple boolean cheek or checks.
Second once you are in the catch block you are kind of in problem since all you can do is print an error to the user or yourself, if you want to go on parsing and checking, you can't...
and last but not least (I'm sure there are reasons I'm not thinking of) except for the message you might get with the exception u are never to sure where it came from...
Are you parsing the JSON yourself? If so, I suggest using an external framework to do the work for you. I use Json-framework in a few of my own projects and it does the job just fine.
http://code.google.com/p/json-framework/

iphone: Caching an NSMutableArray?

I'm currently writing a Twitter client for iPhone and need a way to cache the public timeline. The data fetched is stored as 'Status' objects in an NSMutableArray.
The NSMutableArray stores 20 objects at a time.
What is the best way to do this?
You will probably want to use Core Data. You'll need to create an entity for each tweet, and then store that in your database. There is quite a lot of documentation and sample code on Core Data out there; start at Apple's Samples page.
If you don't want to play with one of the frameworks already mentioned (SQLitePersistentObjects and CoreData), you could implement your own using the NSCoding protocol on your status objects. The array should already implement NSCoding for archiving/unarchiving.
If you want to start quickly try SQLitePersistentObjects.
If you never plan to go over 20 objects you could (slightly) violate some rules from the gods of apple, and use NSUserDefaults - likely the easiest one to implement, but as the name implies, made for things like user settings, so don't use for big piles of info.
Disclaimer: If you know how to use the others, use them, this one is kinda the lazy way if you don't want to learn something better but more difficult.

New to Core Data for iphone

I am new to the iphone platform and am creating an app that retrievals a rss feed and displays it in a UITableView. I have gotten this working perfectly (or rather, the way I wanted). What I was thinking was I would store the current feed items on the phone so that it would initally load the old items it has stored while it got the new feed, then parse the new feed and add the new items and refresh the TableView. I was going to use Core Data to store it the old feed items because it would be a good way of learning Core Data and it would be an appropriate use of Core Data. However, I am having a difficult time learning how to use Core Data and connecting it with the Table/Array.
I have already googled and looked on stackoverflow for tutorials but have yet to find anything that explains it in a way I really understand. Any explanation of the overall steps that it takes to add Core Data to an existing app would be greatly appreciated. Full-blown detail are not necessary (but would also be useful). I'm just not very experienced with SQL or storing of data in such a manner and am having trouble wrapping my head around how the whole concept of Core Data works and how it connects to everything.
Also, any better method of doing what I'm trying to accomplish would also be appreciated.
There exist Xcode templates for Core Data-based applications; these are a great start to getting Core Data off the ground. However, it sounds like you want to integrate Core Data into your existing app, so you'll need to...
Add three main Core Data objects: the managed object context (MOC), the managed object model (MOM), and the persistent store coordinator (PSC). These need to be accessible wherever you want Core Data available, so either in your app delegate or, more preferably, in the controller or data source for your table view.
Create a MOM in Xcode. This will be a file of type .xcdatamodel, and it's an object graph that defines all the Core Data entities you want in your app.
Use NSFetchedResultsController (as suggested by Louis Gerbarg) to get data out of Core Data and display it into your table view.
Add code in your existing RSS-fetching-and-parsing routines to store new Core Data objects back into the store, when appropriate.
A good way to start is just to create a new Core Data application and play around with it a bit; you can also look at Apple's fantastic resources on the subject, like the Core Data Programming Guide and the sample apps Recipes and Locations. (Developer registration may be required.)
One last thing to note is that for the most part, a lot of the Core Data code you need to add can be ripped straight out of one of the Xcode template apps and pasted into your program (this holds especially true for the accessors for the three Core Data objects you need). Be careful not to use code you don't understand, though.
If you are using CoreData to populate a UITableView you really want to use NSFetchedResultsController as opposed to trying to populate and sync array yourself. The documentation for NSFetchedResultsController includes links to several CoreData tutorials, including onces that populate table views.
NSFetchedResultsController is still a bit buggy and requires fragile workarounds. I would start with the simpler iPhone Core Data "location" tutorial before moving on to the Books tutorial.
Also, any better method of doing what I'm trying to accomplish would also be appreciate
yes, it sounds like Core Data might be overkill for your application. Assuming your feed items are stored in a collection object you can easily use OSX's built in serializaition.
Been noted in other Stack-Overflow posts, but I can highly recommend the Prag Prog book "Core Data: Apple's API for Persisting Data on Mac OS X" - most is also relevant to iPhone Core Data apps; there is a whole chapter on creating an iPhone app too.
http://pragprog.com/titles/mzcd/core-data