Try the search, it's linked to some great forums

Thursday, June 20, 2013

JSON / RestKit API Notes

These are notes for installing and using REST (Representational State Transfer).  REST is an API that allows you to translate Web services into coreData within an iPhone app and back the other way.
At its core, RestKit is a system for binding your application's data model with a remote object representation retrieved via HTTP. RKGist tutorial RayWenderlich


CocoaPods - Is an library management tool used in Xcode in conjunction with REST.  It creates a Podfile textfile that creates the dependancies that you specify there.  It is built with the commandline tool.  These following Ray Wenderlich tutorials are great introductions;
open -e Podfile - opens the Podfile in textEdit for libraries & dependencies
pod install - installs new dependencies

SimpleURLConnections.xcodeProj -> Apple's demo using NSURLConnection GET (download) PUT/POST (upload) commands to create a very simple network connection to a server.

Cloning a repository for a GitHub project
  1. Open a terminal and change to the directory where you want the code
  2. Clone the repo by typing git clone git://github.com/dcgrigsby/luckynumbers.git
 git clone git://github repository URL - creates a clone of the project in the directory that you are in

Let's do a simple JSON tutorial first.
JSON - JavaScript Object Notation is a widely used framework for parsing data off the web.  Using this tutorial;
Apple now has it's own JSON implementation called - NSJSONSerialization class

A good source of data in either XML or JSON is The Geonames, geographical database with over 8 million entries. You can join their web service, and access huge data sets including WikaPedia.
Here some links you could find useful: username = clamb
GeoNames User Manual : http://www.geonames.org/manual.html
GeoNames Blog : http://geonames.wordpress.com
GeoNames Forum : http://forum.geonames.org
GeoNames Mailinglist : http://groups.google.com/group/geonames

3rd Party Framework that provides a wrapper class:
http://www.infinite-loop.dk/developer/ilgeonames/

Some examples of XML requests;
Returns all zipcode place names within 10km of zip code=95062 (Santa Cruz):http://api.geonames.org/findNet providesarbyPostalCodes?postalcode=95062&country=US&radius=10&username=clamb
Example for a tourism hierarchy, islands for the Canaries:
http://api.geonames.org/children?geonameId=2593110&username=clamb&hierarchy=tourism
Result : returns a list of wikipedia entries as xml document near Santa Cruz:
http://api.geonames.org/findNearbyWikipedia?lat=37&lng=-122&username=clamb





Sunday, June 9, 2013

Memory Management

This post contains a series of notes, links and tips on memory management in Objective-C.

Reference links
* Great intro to memory management - http://maniacdev.com/2009/07/video-tutorials-on-objective-c-memory-management
* Apple's Memory Usage Guidelines - https://developer.apple.com/library/mac/#documentation/Performance/Conceptual/ManagingMemory/Articles/FindingLeaks.html
* A truly great Instruments Tutorial - http://www.raywenderlich.com/23037/how-to-use-instruments-in-xcode


Notes
* retainCount is a property of NSObject that is used by the system to manage an object's memory.  It is essentially the count of other objects that have a reference to that object.
   [anObject retainCount] returns an integer retain count for anObject
   [anObject retain] increases the count by 1
   [anObject release] decreases the count by 1
   When the count = 0 the system deallocates the memory for that object
* Rule #1 - alloc, new & copy create a new object with retainCount = 1.  Whenever you create an object with one of these methods, your are responsible for releasing that object.
* autoRelease is a method that adds your object to the autoRelease pool where it is released at the end of a program cycle.  It simplifies your task of having to release your objects.
* Memory leaks are blocks of allocated memory that the program no longer references. Leaks waste space by filling up pages of memory with inaccessible data and waste time due to extra paging activity. Leaked memory eventually forces the system to allocate additional virtual memory pages for the application, the allocation of which could have been avoided by reclaiming the leaked memory. (by Apple's Guidelines above)
* For apps that use malloc, memory leaks are bugs and should always be fixed. For apps that use only Objective-C objects, the compiler’s ARC feature deallocates objects for you and generally avoids the problem of memory leaks. However, apps that mix the use of Objective-C objects and C-based structures must manage the ownership of objects more directly to ensure that the objects are not leaked. (by Apple's Guidelines above)



Tips
  • unbounded memory growth - This happens where memory continues to be allocated and is never given a chance to be deallocated.  Use heap shot analysis to troubleshoot (see rayWenderlich tutorial above)
  •