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

Wednesday, March 27, 2013

Custom mapTiles and Building Maps in MapBox & TileMill

This is a quick mashup of details needed to build a custom map using;
  • Beautiful artistic map tiles from Stamen Design
  • Integrated into your own custom map tiles with TileMill
  • And built out as a completed annotated map with MapBox
This is a simple demo for building a small map of Farmer's Markets to be published in a local omnivore quarterly.

Embed code for Stamen watercolor map;

To use these tiles, just include our JavaScript alongside your favorite mapping library:
<script type="text/javascript" src="http://maps.stamen.com/js/tile.stamen.js?v1.2.1">
</script>

 Then, follow the instructions below for your preferred library:
OpenLayers is a hefty and featureful mapping library for use with a variety of GIS applications. View the example.

// replace "toner" here with "terrain" or "toner"
var layer = new OpenLayers.Layer.Stamen("watercolor");
var map = new OpenLayers.Map("element_id");
map.addLayer(layer);


Creating embedded code (iFrames) for custom maps

This is a description including code snippets of how to create embed code for other people to insert into their web pages.  It is based on the work we are doing with GPSVisualizer, but can be used to embed an URL that is available to an online server (like our SCNewspaperTaxi website, or a file with a URL on our Google Drive).

This is the FAQ for GPPSVisualizer:
By far the easiest solution is to put the map in an "inline frame" using the <IFRAME> tag. This creates a "window" in your page into which you can load another file (more info about IFRAMEs). The advantage of doing this is that the DIVs and margins and styles and whatnot will be completely isolated from the rest of the structure of your page; also, you don't have to edit the attributes of the <BODY> or <HTML> tags, which you would have to do if you tried to merge the GPS Visualizer code into your Web page. (The only disadvantage, and one which would only affect "power users," is that if you want to create objects that interact with the map -- for instance, a list of waypoints, or a control that will re-center the map -- those cannot be outside the IFRAME.)
Another advantage to IFRAMEs (as opposed to cutting and pasting bits of HTML into your page) is that you can place as many of them on your page as you want; because they are isolated from each other, there shouldn't be any conflicts even if all the maps have identically named parts.


Here's a sample <IFRAME> tag; the anchor in the middle will only be displayed if the browser does not support inline frames:
<iframe src="my_map.html" width="600" height="400" marginwidth="0" marginheight="0" scrolling="no" frameborder="0">
 <a href="my_map.html">Click here for the map</a>
</iframe>


Here’s an example from a Google Maps embed code:
</iframe>
<br /><small>View <a href="https://maps.google.com/maps/ms?msa=0&amp;msid=204112771159932432535.0004d6a3eb52759422f2e&amp;hl=en&amp;ie=UTF8&amp;ll=36.987644,-121.759922&amp;spn=0.271253,0.722587&amp;t=m&amp;iwloc=0004d6a410726c0cee96f&amp;source=embed" style="color:#0000FF;text-align:left">Santa Cruz Beer Map </a> in a larger map</small>


demo map URL saved in SCNewspaperTaxic.com
http://santacruznewspapertaxi.com/wp-content/uploads/2013/03/xxxxDistributionGeocoded04.html


Here’s the code for our 1st iFrame (hopefully):
<iframe src="http://santacruznewspapertaxi.com/wp-content/uploads/2013/03/xxxxDistributionGeocoded04.html" width="600" height="400" marginwidth="0" marginheight="0" scrolling="no" frameborder="0">
 <a href="http://santacruznewspapertaxi.com/wp-content/uploads/2013/03/xxxxxxDistributionGeocoded04.html">Click here for the map</a>
</iframe>