<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" xml:lang="en-US"><title type="text">MKBlog</title><link rel="alternate" type="text/html" href="http://blog.mugunthkumar.com" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/MugunthKumar" /><subtitle type="html">iOS development blog and Usability Guidelines</subtitle><updated>2013-05-22T07:05:38+00:00</updated><generator>http://wordpress.org/?v=3.5.1</generator><sy:updatePeriod xmlns:sy="http://purl.org/rss/1.0/modules/syndication/">hourly</sy:updatePeriod><sy:updateFrequency xmlns:sy="http://purl.org/rss/1.0/modules/syndication/">1</sy:updateFrequency><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/MugunthKumar" /><feedburner:info uri="mugunthkumar" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><link rel="license" type="text/html" href="http://creativecommons.org/licenses/by-sa/3.0/" /><feedburner:emailServiceId>MugunthKumar</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><entry><title type="text">iOS-Framework: Einführung in MKNetworkKit (German Translation of MKNetworkKit documentation)</title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MugunthKumar/~3/FAzucGBfNAQ/" /><category term="Products" /><category term="german" /><category term="mknetworkkit" /><category term="translation" /><author><name>Mugunth Kumar</name></author><updated>2013-04-25T00:21:18-07:00</updated><id>http://blog.mugunthkumar.com/?p=2061</id><summary type="html">Translation by Jonas Pencke (@jonaspencke) iOS-Framework: Einführung in MKNetworkKit Wie genial wäre es, wenn sich ein Networking-Framework automatisch ums Cachen der Antworten kümmern würde? Wie genial wäre es, wenn sich ein Networking-Framework automatisch alle noch auszuführenden Operationen merken würde, wenn der Client offline geht? Im Offline-Zustand könnten somit Tweets favorisiert oder Feeds als gelesen markiert [...]&lt;div class='yarpp-related-rss yarpp-related-none'&gt;

No related posts.
&lt;img src='http://yarpp.org/pixels/8b86e81420c6776e456ee5dbf4b38381'/&gt;
&lt;/div&gt;</summary><content type="html">&lt;p&gt;&lt;/p&gt;&lt;p&gt;Translation by Jonas Pencke (&lt;a href="https://twitter.com/jonaspencke"&gt;@jonaspencke&lt;/a&gt;)&lt;/p&gt;
&lt;span id="iOS-Framework:_Einfhrung_in_MKNetworkKit"&gt;&lt;h2&gt;iOS-Framework: Einführung in MKNetworkKit&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;Wie genial wäre es, wenn sich ein Networking-Framework automatisch ums Cachen der Antworten kümmern würde?&lt;br /&gt;
Wie genial wäre es, wenn sich ein Networking-Framework automatisch alle noch auszuführenden Operationen merken würde, wenn der Client offline geht?&lt;br /&gt;
Im Offline-Zustand könnten somit Tweets favorisiert oder Feeds als gelesen markiert werden und das Networking-Framework würde sich um die Aufnahme aller Operationen kümmern, sobald das Gerät wieder online ist. Und dies alles ohne zusätzlichen Programmieraufwand? Herzlich Willkommen bei MKNetworkKit.&lt;/p&gt;
&lt;span id="Was_ist_MKNetworkKit"&gt;&lt;h2&gt;Was ist MKNetworkKit?&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;MKNetworkKit ist ein in Objective-C geschriebenes Networking-Framework, welches sich nahtlos integriert, Blocks verwendet, ARC ready ist und sich einfach verwenden lässt. Inspiriert wurde MKNetworkKit von zwei anderen bekannten Networking-Frameworks,  namens ASIHTTPRequest und AFNetworking. Der Funktionsumfang beider wurde zusammengeführt und mit neuen zusätzlichen Funktionen erweitert. Im Vergleich mit anderen Frameworks schreibt man beim Verwenden von MKNetworkKit ein wenig mehr Code, was jedoch zu klarerem bzw. besser lesbarem Code führt. Mit MKNetworkKit ist es schwierig, unschönen Networking-Code zu schreiben.&lt;/p&gt;
&lt;span id="Funktionen"&gt;&lt;h2&gt;Funktionen&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;&lt;span style='text-decoration:underline;'&gt;Extremes Leichtgewicht&lt;/span&gt;&lt;br /&gt;
Das komplette Framework besteht im Wesentlichen aus 2 Hauptklassen und ein paar Kategorien. Aus diesem Grund sollte das Anpassen von MKNetworkKit ziemlich einfach  von der Hand gehen.&lt;/p&gt;
&lt;p&gt;&lt;span style='text-decoration:underline;'&gt;Die gesamte Applikation benutzt eine einzige globale Queue&lt;/span&gt;&lt;br /&gt;
Apps die sehr stark von einer Internet-Verbindung abhängen, müssen sich um die Optimierung bei der Anzahl der gleichzeitig genutzten Netzwerk-Operationen kümmern. Bisher gibt es leider kein einziges Networking-Framework, was dies von Haus aus korrekt erledigt. Nachfolgend gebe ich euch ein Beispiel für Probleme, die auftreten können, wenn die Anzahl der gleichzeitig ablaufenden Netzwerk-Operationen in einer App nicht kontrolliert bzw. optimiert wird.&lt;br /&gt;
Angenommen wir möchten einige Fotos auf einen Server (z.B. Color oder Batch) laden. Die meisten mobilen Netzwerke (3G) sind dabei auf maximal 2 gleichzeitige HTTP-Verbindungen von der gleichen IP-Adresse beschränkt. Das bedeutet, dass von einem Gerät gleichzeitig nicht mehr als 2 HTTP-Verbindungen in einem 3G Netzwerk geöffnet werden können. Bei EDGE ist es oft sogar noch schlimmer bzw. sind weniger Verbindungen erlaubt. In den meisten Fällen verfügt man dort nur über eine einzige Verbindung. Das Limit von 6 in einem gewöhnlichen Breitbandnetz (Wifi) wirkt demgegenüber relativ hoch. Da die Verbindung von einem iDevice mit einem Wifi-Netzwerk jedoch nicht immer gesichert ist, sollte man auch auf eingeschränktere Netzwerk-Verbindung vorbereitet sein. Im Normalfall sollte das iDevice jedoch mit einem 3G-Netzwerk verbunden sein. Demzufolge ist es möglich 2 Fotos gleichzeitig hoch zu laden. Dabei ist die langsame Upload-Geschwindigkeit nicht das größte Problem. Das eigentliche Problem tritt auf, wenn z.B. ein View geöffnet wird, der mehrere Thumbnails (sagen wir auf einem anderen View) lädt, während im Hintergrund die anderen Upload-Operationen noch laufen. Wenn nun die Queue-Größe über die App hinweg nicht ordnungsgemäß gehandhabt wird, können die Download-Operationen der Thumbnails mit einem Timeout abbrechen, was nicht wirklich sinnvoll ist. Besser wäre es die Download-Operation der Thumbnails zu priorisieren oder solange zu warten, bis der Upload der Fotos fertig gestellt ist, um danach das Laden der Thumbnails zu beginnen. Damit das funktioniert, braucht man eine (einzige) globale Queue für die gesamte App. MKNetworkKit stellt genau dieses Prinzip automatisch sicher, indem es für jede Instanz eine globale Queue anlegt und verwendet. MKNetworkKit ist selbst kein Singleton, aber die globale Queue schon.&lt;/p&gt;
&lt;p&gt;&lt;span style='text-decoration:underline;'&gt;Netzwerk-Aktivitätsanzeige korrekt darstellen&lt;/span&gt;&lt;br /&gt;
Während viele Klassen und Bibliotheken von Drittanbietern ein einfaches In- bzw. Dekrementieren der Anzahl der Netzwerk-Anfragen verwenden, um den Aktivitätsindikator anzuzeigen, basiert die MKNetworkKit Aktivitätsanzeige auf dem Prinzip der global geteilten Queue. Durch das Observieren (KVO) der “operationCount” Property, wird die Aktivitätsanzeige immer dargestellt, solange noch eine Operation in der gemeinsamen Queue abgearbeitet wird. Für den Entwickler entfällt damit das manuelle Verwalten der Netzwerk-Aktivitätsanzeige.&lt;/p&gt;
&lt;p&gt;&lt;span style='text-decoration:underline;'&gt;Automatisches Testen der Queue-Größe&lt;/span&gt;&lt;br /&gt;
Vorhin wurde erwähnt, dass die meisten mobilen Netzwerke gleichzeitig nicht mehr als 2 Verbindungen erlauben. Aus diesem Grund sollte bei einer 3G Netzwerkverbindung die Queue-Größe auf 2 gesetzt werden. Dies wird automatisch von MKNetworkKit erledigt. Verschlechtert sich die Verbindung von Wifi zu 3G/EDGE/GPRS, dann passt MKNetworkKit für dich die Anzahl der erlaubten gleichzeitigen Verbindungen an &amp;#8211; in diesem Fall auf 2. Selbstverständlich wird die Queue-Größe wieder zurück auf 6 gesetzt, sobald dem Gerät erneut ein Wifi Netzwerk zur Verfügung steht. Dieser Ansatzes bringt eine erhebliche Performance-Verbesserung beim Laden von Thumbnails (oder mehreren ähnlichen kleinen Anfragen) für eine Foto-Galerie von einem Remote-Server über 3G.&lt;/p&gt;
&lt;p&gt;&lt;span style='text-decoration:underline;'&gt;Automatisches Caching&lt;/span&gt;&lt;br /&gt;
MKNetworkKit kann automatisch alle “GET”-Anfragen cachen. Wird die gleiche Anfrage ein weiteres Mal ausgeführt, so ruft MKNetworkKit den “CompletionHandler” mit der gecachten Version der Antwort (wenn diese vorliegt) direkt auf. Wenn die Daten vom Server erfolgreich geladen wurden, wird der “CompletionHandler” ein weiteres Mal mit der neuen Antwort aufgerufen. Das bedeutet, dass das Cache-Handling nicht manuell gemacht werden muss. Alles was dafür notwendig ist, ist das Aufrufen der folgenden Methode.&lt;/p&gt;
&lt;p&gt;In von MKNetworkEngine abgeleiteten Klassen können bei Bedarf Methoden überschrieben werden, um den Cache-Ordner und die “in-memory” Cache-Kosten einzustellen.&lt;/p&gt;
&lt;p&gt;&lt;span style='text-decoration:underline;'&gt;Freezen (einfrieren) von Operationen&lt;/span&gt;&lt;br /&gt;
MKNetworkKit bietet die Möglichkeit Netzwerk-Operationen einzufrieren. Wenn eine Operation eingefroren wird, z.B. beim Verlust der Netzwerkverbindung, werden die Operation automatisch serialisiert und wieder ausgeführt, sobald das Gerät wieder online kommt. Dies ist vergleichbar mit “Drafts” in einem Twitter- oder Email-Client.&lt;br /&gt;
Wenn ein Tweet gepostest wird, kann der Netzwerk-Aufruf als “freezable” markiert werden und MKNetworkKit übernimmt automatisch das Einfrieren und Wiederherstellen der Anfragen. Das heißt, dass fast kein extra Code geschrieben werden muss, um die Tweets später abzuschicken. Dies kann auch für andere Operationen, wie dem Favorisieren eines Tweets oder Sharen eines Posts von einem Google Reader Client, Hinzufügen eines Links zu Instapaper oder ähnlichen Operationen genutzt werden.&lt;/p&gt;
&lt;p&gt;&lt;span style='text-decoration:underline;'&gt;Führt exakt eine Operation für gleiche Anfragen aus&lt;/span&gt;&lt;br /&gt;
Beim Laden von Thumbnails (von einem Twitter Stream), wird oft für jedes einzelne Avatar Bild eine neue Anfrage erzeugt. In der Realität sollte jedoch die Anzahl der Anfragen gleich der einzigartigen URLs sein. MKNetworkKit führt jede GET Anfrage die in die Queue kommt nur exakt einmal aus. HTTP POST-Anfragen werden logischerweise nicht von MKNetworkKit gecacht.&lt;/p&gt;
&lt;p&gt;&lt;span style='text-decoration:underline;'&gt;Image Caching&lt;/span&gt;&lt;br /&gt;
MKNetworkKit kann einfach zum Cachen von Thumbnails genutzt werden. Durch das Überschreiben einiger weniger Methoden kann die Anzahl der Bilder, die im in-Memory-Cache gehalten werden sollen und der Speicherort im Cache-Directory eingestellt werden.   Das Überschreiben dieser Methoden ist aber komplett optional.&lt;/p&gt;
&lt;p&gt;&lt;span style='text-decoration:underline;'&gt;Performance/Leistung&lt;/span&gt;&lt;br /&gt;
Nur ein einziges Wort: Geschwindigkeit. Das Cachen von MKNetworkKit ist nahtlos (seamless). Es arbeitet wie NSCache, jedoch mit der Ausnahme, dass beim Auftreten einer Speicherwarnung der in-Memory-Cache in den Cache Ordner geschrieben wird.&lt;/p&gt;
&lt;p&gt;&lt;span style='text-decoration:underline;'&gt;Volle Unterstützung von Objective-C ARC&lt;/span&gt;&lt;br /&gt;
Normalerweise wird für ein neues Projekt ein neues Netzwerk-Framework genommen. MKNetworkKit ist eigentlich nicht dafür gedacht existierende Frameworks zu ersetzen (obwohl es möglich ist, ist es meistens ein recht aufwendiger bzw. ermüdender Job). Neue Projekte sollten eigentlich immer ARC verwenden. Als dieser Artikel geschrieben wurde, war MKNetworkKit das einzige Networking-Framework, das komplett ARC fertig ist. ARC basierte Speicherverwaltung ist generell um eine Größenordnung schneller als die Speicherverwaltung ohne ARC.&lt;/p&gt;
&lt;p&gt;&lt;span style='text-decoration:underline;'&gt;Wie wird es benutzt&lt;/span&gt;&lt;br /&gt;
Ok genug des Eigenlobes. Lasst uns schauen, wie das Framework benutzt werden kann.&lt;/p&gt;
&lt;span id="Hinzufgen_des_MKNetworkKits"&gt;&lt;h2&gt;Hinzufügen des MKNetworkKits&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;1.	Ziehe den MKNetworkKit Ordner in dein Projekt.&lt;br /&gt;
2.	Füge das CFNetwork.Framework, SystemConfiguration.Framework und Security.Framework hinzu.&lt;br /&gt;
3.	Inkludiere MKNetworkKit.h zu deiner PCH Datei&lt;br /&gt;
4.	Lösche die NSAlert+MKNetworkKitAdditions.h Datei falls es ein iOS Projekt ist.&lt;br /&gt;
5.	Lösche die UIAlerView+MKNetworkKitAdditions.h Datei falls es ein Mac Projekt ist.&lt;/p&gt;
&lt;p&gt;Das war’s. Mit nur 5 Core Dateien verfügst du über ein mächtiges Networking-Kit.&lt;/p&gt;
&lt;span id="Klassen_in_MKNetworkKit"&gt;&lt;h3&gt;Klassen in MKNetworkKit&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;1.	MKNetworkOperation&lt;br /&gt;
2.	MKNetworkEngine&lt;br /&gt;
3.	Verschiedene Helferklassen (Apple’s Verfügbarkeits-Klasse (Reachability)) und Kategorien&lt;/p&gt;
&lt;p&gt;Ich glaube an Einfachheit und Apple hat den schweren Job beim Schreiben des richtigen Networking-Codes bereits erledigt. Was ein Drittanbieter Netzwerk-Framework ermöglichen sollte, ist ein elegantes Queue basiertes Networking mit optionalem Caching. Ich glaube daran, dass jedes Drittanbieter-Framework weniger als 10 Klassen besitzen sollte (unabhängig davon ob es sich dabei um Networking handelt oder eine UIKit Ersetzung oder irgend etwas anderes). Mehr als das ist zu aufgebläht. Three20 sowie ShareKit sind Beispiele für eine aufgeblähte bzw. überfrachtete Bibliothek. Es kann sein, dass sie an sich gut sind, aber trotzdem bleiben sie riesig und total aufgebläht. ASIHttpRequest oder AFNetworking sind im Vergleich zu RESTKit schlank und somit wirkliche Leichtgewichte. Ebenfalls ist JSONKit ein Leichtgewicht, anders als TouchJSON (oder alle anderen TouchCode Bibliotheken). Es kann natürlich sein, dass nur ich Wert darauf lege, aber in meinem Source-Code soll nicht jede dritte Zeile von einer Drittanbieter-Bibliothek stammen.&lt;/p&gt;
&lt;p&gt;Die Schwierigkeit bei einem großen und unüberschaubarem Framework ist, das Verständnis für die interne Funktionsweise und die Möglichkeit das Framework an die eigenen Bedürfnisse anzupassen (falls nötig). Meine Frameworks (wie MKStoreKit, das In-App-Verkäufe zu deiner App hinzufügt) konnten immer super einfach verwendet werden und ich glaube, dass dies auch für MKNetworkKit gilt. Um MKNetworkKit zu benutzen, musst du nur die öffentlichen Methoden der beiden Klassen MKNetworkOperation und MKNetworkEngine kennen. MKNetworkOperation ist der ASIHttpRequest Klasse recht ähnlich. Es ist eine Unterklasse von NSOperation und bilder einen Wrapper um deine Request- und Response-Klassen. In einer Applikation wird dann für jede benötigte Netzwerkoperation eine neue MKNetworkOperation erzeugt.&lt;/p&gt;
&lt;p&gt;MKNetworkEngine ist eine Pseudo-Singleton Klasse, die die Netzwerk-Queue der Applikation verwaltet. Es ist in dem Sinne ein Pseudo-Singleton, da für einfache Anfragen die MKNetworkEngine Methoden direkt genutzt werden können. Für größere Anpassungen sollte jedoch eine von MKNetworkEngine ableitende Klasse erzeugt werden. Jede von MKNetworkEngine ableitende Klasse besitzt von Haus aus ihr eigenes Reachability Objekt, das sie über Server-Verfügbarkeitsänderungen notifiziert. Für jeden einzelnen REST-Server, den du verwendest, sollte eine eigene abgeleitete Klasse von MKNetworkEngine erzeugt werden. Es ist in diesem Sinne Pseudo-Singleton, da jede einzelne Anfrage, in egal welcher Subklasse, durch die eine globale Queue geht.&lt;/p&gt;
&lt;p&gt;Instanzen deiner MKNetworkEngines können wie die CoreDataManagedObjectContext Klasse im “ApplicationDelegate” gespeichert werden. Beim Verwenden von MKNetworkKit werden Unterklassen von KNetworkEngine erzeugt, um die Netzwerk-Anfragen logisch zu gruppieren. Das bedeutet, dass alle Yahoo-relevanten Methoden in einer gemeinsamen Klasse und alle zu Facebook gehörenden Methoden in einer anderen Klasse liegen. Im Folgenden schauen wir uns drei Beispiele für die mögliche Verwendung des Frameworks an.&lt;/p&gt;
&lt;span id="Beispiel_1"&gt;&lt;h3&gt;Beispiel 1&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;Lasst uns nun eine “YahooEngine” erzeugen, die aktuelle Wechselkurse von “Yahoo finance“ lädt.&lt;/p&gt;
&lt;span id="Schritt_1:"&gt;&lt;h4&gt;Schritt 1:&lt;/h4&gt;&lt;/span&gt;
&lt;p&gt; Erzeuge einer “YahooEngine”-Klasse als abgeleitete Klasse von MKNetworkEngine. Die init-Methode der MKNetworkEngine bekommt als Parameter einen Host-Namen und bei Bedarf einen benutzerdefinierten Header. Die benutzerdefinierten Header sind optional und können “nil” sein. Wenn ein eigener REST Server geschrieben werden soll (anders als in diesem Fall), könnte dort die Client-App-Version und andere sonstige Daten, wie ein Client-Identifier hinzugefügt werden. &lt;/p&gt;
&lt;p&gt;&lt;img style="display:block; margin-left:auto; margin-right:auto;" src="http://iostraining.sg/wp-content/uploads/2013/04/settings-headers.png" alt="Settings headers" title="settings headers.png" border="0" width="481" height="100" /&gt;&lt;/p&gt;
&lt;p&gt;Dabei ist zu beachten, dass yahoo einen eigentlich nicht zwingt einen “x-client-identifier” im Header mitzuschicken. Zum Zeigen des Features wurde es aber im obigen Code-Beispiel hinzugefügt.&lt;/p&gt;
&lt;p&gt;Da der komplette Code ARC verwendet, ist es die Aufgabe des Entwicklers eine Engine Instanz zu speichern (starke Referenz). &lt;/p&gt;
&lt;p&gt;Wenn eine abgeleitete Klasse von MKNetworkEngine erzeugt wird, wird dazu automatisch die Reachability-Implementierung hinzugefügt. Das bedeutet, wenn der Server nicht mehr zu erreichen ist oder irgendwelche unvorhersehbaren Umstände eintreten, z.B. dass der Host nicht erreichbar ist, werden die Anfragen automatisch eingefroren. Für weitere Informationen bezüglich des Einfrieren von Operationen, schaut in der Sektion “Freezing Operations” etwas weiter unten nach.&lt;/p&gt;
&lt;span id="Schritt_2:"&gt;&lt;h4&gt;Schritt 2:&lt;/h4&gt;&lt;/span&gt;
&lt;p&gt; Design der Engine Klasse (Trennung der Zuständigkeiten)&lt;br /&gt;
Nun kümmern wir uns um das Schreiben der “YahooEngine”-Methoden, welche die Wechselkurse abfragen. Die Engine-Methoden werden aus dem ViewController heraus aufgerufen. Eine gute Design-Angewohnheit ist, sicherzustellen, dass die Engine-Klasse die URL/HTTP-Headers nicht an die aufrufende Klasse weitergibt bzw. offenlegt. Der View braucht keine Informationen über die URL-Endpunkte oder andere Parameter. Das bedeutet, dass Parameter in Methoden der “YahooEngine” die Währungen und die Anzahl der Währungseinheiten sein sollten. Der Rückgabewert dieser Methode könnte ein double sein, der den Wechselrate-Faktor beschreibt und eventuell den Zeitstempel, wann es abgefragt wurde. Da die Operationen nicht synchron ausgeführt werden, sollten die Werte &lt;/p&gt;
&lt;p&gt;&lt;img style="display:block; margin-left:auto; margin-right:auto;" src="http://iostraining.sg/wp-content/uploads/2013/04/code-snippet-1.png" alt="Code snippet 1" title="code snippet 1.png" border="0" width="481" height="56" /&gt;&lt;/p&gt;
&lt;p&gt;mit Hilfe von Blocks zurückgegeben werden. Ein Beispiel hierfür wäre das folgende:&lt;/p&gt;
&lt;p&gt;&lt;img style="display:block; margin-left:auto; margin-right:auto;" src="http://iostraining.sg/wp-content/uploads/2013/04/blocks.png" alt="Blocks" title="blocks.png" border="0" width="481" height="42" /&gt;&lt;/p&gt;
&lt;p&gt;Die Basisklasse MKNetworkEngine definiert drei Typen von Block-Methoden, siehe unten:&lt;br /&gt;
In unserer “YahooEngine” nutzen wir eine neue Art von Block, “CurrencyResponseBlock” &lt;/p&gt;
&lt;p&gt;&lt;img style="display:block; margin-left:auto; margin-right:auto;" src="http://iostraining.sg/wp-content/uploads/2013/04/code-block-2.png" alt="Code block 2" title="code block 2.png" border="0" width="481" height="16" /&gt;&lt;/p&gt;
&lt;p&gt;der die Wechselrate zurück liefert. Die Definition sieht wie folgt aus:&lt;br /&gt;
In jeder normalen Applikation sollten eigene Block-Methoden &amp;#8211; ähnlich wie der  “CurrencyResponseBlock” &amp;#8211; zum Zurücksenden von Daten zum View Controller definiert und genutzt werden. &lt;/p&gt;
&lt;span id="Schritt_3:"&gt;&lt;h4&gt;Schritt 3:&lt;/h4&gt;&lt;/span&gt;
&lt;p&gt; Verarbeitung der Daten&lt;br /&gt;
Die Datenverarbeitung, die die vom Server geholten Daten &amp;#8211; unabhängig ob es JSON, XML oder “Binary Plists” sind &amp;#8211; umwandelt, sollte in der Engine durchgeführt werden. Noch einmal, die Controller sollten von dieser Aufgabe befreit werden. Die Engine sollte die Daten in passenden Model-Objekten oder Arrays von Model-Objekten (im Falle von Listen) zurück liefern. JSON/XML sollte deshalb in den Engines zu Modellen umgewandelt werden. Nochmals, um die richtige Aufteilung der Zuständigkeiten sicherzustellen, sollte der ViewController nicht über die Schlüssel (Keys) verfügen, um auf einzelne Elemente im JSON zugreifen zu können.&lt;/p&gt;
&lt;p&gt;Dies fordert das Design der Engine bzw. lässt sich daraus schließen. Die meisten Networking Frameworks zwingen einen nicht, diesem Paradigma des “Separation of Concerns” zu folgen. Wir machen das, weil wir uns um euch kümmern &lt;img src='http://blog.mugunthkumar.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /&gt;  &lt;/p&gt;
&lt;span id="Schritt_4:"&gt;&lt;h4&gt;Schritt 4:&lt;/h4&gt;&lt;/span&gt;
&lt;p&gt; Methoden Implementierung&lt;br /&gt;
Wir werden nun die Implementierungsdetails der Methode diskutieren, die die Währungsumrechnungen durchführt.&lt;/p&gt;
&lt;p&gt;Das Abgreifen der Währungsinformationen von Yahoo ist so einfach wie eine normale GET-Anfrage. Hierfür habe ich ein Makro geschrieben, welches die URL für ein zu &lt;/p&gt;
&lt;p&gt;&lt;img style="display:block; margin-left:auto; margin-right:auto;" src="http://blog.mugunthkumar.com/wp-content/uploads/defines.png" alt="Defines" title="defines.png" border="0" width="481" height="30" /&gt;&lt;/p&gt;
&lt;p&gt;übergebendes Währungsformat formatiert.&lt;br /&gt;
Die Methoden, die in dieser Engine Klasse geschrieben werden, sollten die folgenden Sachen in ebendieser Reihenfolge tun.&lt;/p&gt;
&lt;p&gt;1.	Die URL aus den Parametern zusammenstellen.&lt;br /&gt;
2.	Für die Anfrage ein MKNetworkOperation Objekt erzeugen.&lt;br /&gt;
3.	Die Parameter der Methode setzen.&lt;br /&gt;
4.	“Completion” und “ErrorHandler” zu der Operation hinzufügen (Der “CompletionHandler” ist dabei der richtige Platz, um die zurückgelieferten Antworten zu verarbeiten und in entsprechende Modelle zu konvertieren.)&lt;br /&gt;
5.	Optional können “ProgressHandler” zur Operation hinzugefügt werden. (Oder aber  im  View Controller)&lt;br /&gt;
6.	Falls die Operation ein Datei-Download ist, muss ein Download-Stream (im Normalfall eine Datei) gesetzt werden. Dies ist wiederum optional.&lt;br /&gt;
7.	Wenn die Operation fertig ist, muss das Resultat weitergereicht und die Block-Methode aufgerufen werden, um die Daten zur aufrufenden Methode zurückzugeben.&lt;/p&gt;
&lt;p&gt;&lt;img style="display:block; margin-left:auto; margin-right:auto;" src="http://blog.mugunthkumar.com/wp-content/uploads/code-block-currency.png" alt="Code block currency" title="code block currency.png" border="0" width="481" height="281" /&gt;&lt;/p&gt;
&lt;p&gt;Das ist im Folgenden dargestellt&lt;br /&gt;
Der obige Code formatiert die URL und legt eine MKNetworkOperation an. Nachdem die “Completion” und “ErrorHandler” definiert wurden, wird die Operation durch das Aufrufen der Superklassenmethode “enqueueOperation” in die Queue aufgenommen und liefert eine Referenz davon zurück. Der “ViewController” sollte diese Operation speichern und sie abbrechen, wenn der View aus der View-Hierarchie herausgeschmissen wird. Deshalb sollte, wenn die Engine Methode sagen wir in “viewDidAppear” aufgerufen wird, die Abbruch Operation in “viewWillDisappear” aufrufen. Das Abbrechen der Operation ermöglicht der Queue, andere Operationen des nächsten Views durchzuführen (Denkt dran, dass in einem mobilen Netzwerk nur zwei Operationen gleichzeitig verarbeitet werden können. Deshalb ist das Abbrechen von Operationen, wenn sie nicht mehr benötigt werden, eine Grundvoraussetzung, um Performance und Geschwindigkeit der App sicherzustellen). &lt;/p&gt;
&lt;p&gt;Der View Controller kann zusätzlich (bei Bedarf) einen “ProgressHandler” hinzufügen und darüber das User Interface aktualisieren. Dies ist nachfolgend dargestellt.&lt;/p&gt;
&lt;p&gt;&lt;img style="display:block; margin-left:auto; margin-right:auto;" src="http://blog.mugunthkumar.com/wp-content/uploads/progress-block.png" alt="Progress block" title="progress block.png" border="0" width="481" height="71" /&gt;&lt;/p&gt;
&lt;p&gt;Die MKNetworkEngine besitzt zudem Standardmethoden, um eine Operation nur aus einer URL zu erzeugen. Aus diesem Grund könnte die erste Zeile des Codes auch wie folgt &lt;/p&gt;
&lt;p&gt;&lt;img style="display:block; margin-left:auto; margin-right:auto;" src="http://blog.mugunthkumar.com/wp-content/uploads/create-op.png" alt="Create op" title="create op.png" border="0" width="481" height="30" /&gt;&lt;/p&gt;
&lt;p&gt;geschrieben werden&lt;br /&gt;
Beachten muss man, dass die bei der Initialisierung der Engine Klasse angegebenen Hostnamen automatisch vor die Request-URLs gesetzt werden. &lt;/p&gt;
&lt;p&gt;Das Erzeugen einer POST, DELETE oder PUT Methode ist so einfach wie das Ändern eines Parameters einer http Methode. Die MKNetworkEngine besitzt noch mehr Standardmethoden wie diese. Mehr Informationen findet ihr in den header Dateien. &lt;/p&gt;
&lt;span id="Beispiel_2"&gt;&lt;h3&gt;Beispiel 2&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;Hochladen eines Bildes zu einem Server (zum Beispiel zu TwitPic).&lt;br /&gt;
Lasst uns nun durch ein Beispiel schauen, in welchem ein Bild zu einem Server geschickt wird. Beim Hochladen eines Bildes muss die Operation offensichtlich als “multi-part form data” encodiert werden. Dabei folgt MKNetworkKit einem ähnlichen Pattern wie ASIHttpRequest. Durch den Aufruf der Methode “addFile:forKey:” in der MKNetworkOperation wird der Anfrage eine Datei als “multi-part form data” “hinzugefügt”. Es ist wirklich so einfach.&lt;br /&gt;
MKNetworkOperation hat zudem eine Standardmethode, um ein Bild von einem “NSData” Pointer hinzuzufügen. Das heißt, dass die Methode “addData:forKey:” direkt von einem “NSData” Pointer aufgerufen werden kann, um ein Bild zu einem Server zu schicken. (Interessant ist dies zum Beispiel beim direkten Hochladen eines gerade mit der Kamera geschossenen Bildes.) &lt;/p&gt;
&lt;span id="Beispiel_3"&gt;&lt;h3&gt;Beispiel 3&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;Herunterladen von Dateien in einen lokalen Ordner (Caching).&lt;br /&gt;
MKNetworkKit ermöglicht das einfache Laden einer Datei von einem Remote-Server sowie das Speichern in einer Lokation auf dem iPhone des Benutzers.&lt;br /&gt;
Dafür muss nur der “outputStream” der MKNetworkOperation gesetzt werden und man ist &lt;/p&gt;
&lt;p&gt;&lt;img style="display:block; margin-left:auto; margin-right:auto;" src="http://blog.mugunthkumar.com/wp-content/uploads/stream.png" alt="Stream" title="stream.png" border="0" width="481" height="57" /&gt;&lt;/p&gt;
&lt;p&gt;fertig.&lt;br /&gt;
Es können mehrere “Output Streams” zu einer einzelnen Operation hinzugefügt werden, um die gleiche Datei an mehreren Stellen zu speichern (zum Beispiel im Cache Ordner sowie im “Working” Ordner)&lt;/p&gt;
&lt;span id="Beispiel_4"&gt;&lt;h3&gt;Beispiel 4&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;Thumbnail-Caching&lt;br /&gt;
Beim Herunterladen von Bildern muss eher eine absolute URL als ein Pfad angegeben werden. DIE MKNetworkEngine hat dafür eine Standard-Methode. Verwende einfach  die  Methode “operationWithURLString:params:httpMethod:” um eine Netzwerk-Operation mit einer absoluten URL zu erzeugen.&lt;br /&gt;
Die MKNetworkEngine ist intelligent, da sie mehrere GET-Anfragen zur gleichen URL zu einer einzigen zusammenführt und alle Blocks, wenn die eine Operation fertig ist, notifiziert. Dies verbessert drastisch die Geschwindigkeit beim Abgreifen von Bild-URLs für bekannte Thumbnails.&lt;/p&gt;
&lt;p&gt;Leite die MKNetworkEngine ab und überschreibe den Bild Cache Ordner und die Cache-Kosten. Wenn diese beiden Einstellungen nicht individuell angepasst werden sollen, können auch direkt die MKNetworkEngine-Methoden zum Download von Bildern genutzt werden. Dies ist sogar empfehlenswert.&lt;/p&gt;
&lt;p&gt;Caching Operationen&lt;br /&gt;
MKNetworkKit speichert standardmäßig alle Anfragen zwischen. Alles was dafür getan werden muss, ist das Cachen für die Engine anzuschalten. Wenn eine GET-Anfrage ausgeführt wird und die Antwort vorher bereits zwischengespeichert wurde, dann wird der “CompletionHandler” sofort mit der gecachten Antwort aufgerufen. Um zu wissen, ob die Antwort eine zwischengespeicherte ist oder nicht, kann die Methode “isCachedResponse” &lt;/p&gt;
&lt;p&gt;&lt;img style="display:block; margin-left:auto; margin-right:auto;" src="http://blog.mugunthkumar.com/wp-content/uploads/cache.png" alt="Cache" title="cache.png" border="0" width="481" height="196" /&gt;&lt;/p&gt;
&lt;p&gt;genutzt werden. Dies ist im Folgenden illustriert:&lt;/p&gt;
&lt;p&gt;Freezing-Operationen&lt;br /&gt;
Eines der wahrscheinlich interessantesten Features von MKNetworkKit ist die integrierte Möglichkeit, Operationen einfrieren zu können. Alles was dafür benötigt wird, ist die Operation als “freezable” zu markieren. Dies erfordert quasi keinen Aufwand.&lt;br /&gt;
Eingefrorene Operationen werden automatisch serialisiert, wenn die Netzwerk-Verbindung abbricht, und wieder aufgenommen, wenn eine neue Netzwerk-Verbindung besteht. Denkt über die sich bietenden Möglichkeiten nach, z.B. kann ein Tweet als Favorit markiert werden während man offline ist und die Operation wird später, wenn man wieder online ist, automatisch ausgeführt.&lt;br /&gt;
Eingefrorene Operationen werden ebenfalls auf der Festplatte persistiert, wenn die App in den Hintergrund tritt und auch automatisch fortgeführt, wenn die App wieder in den Vordergrund kommt.&lt;/p&gt;
&lt;p&gt;Standardmethoden der MKNetworkOperation&lt;br /&gt;
Die Klasse MKNetworkOperation bietet folgende Standardmethoden, um das Daten-Format der Antwort zu bestimmen:&lt;/p&gt;
&lt;p&gt;1.	responseData&lt;br /&gt;
2.	responseString&lt;br /&gt;
3.	responseJSON (only on iOS 5)&lt;br /&gt;
4.	responseImage&lt;br /&gt;
5.	responseXML&lt;br /&gt;
6.	error&lt;/p&gt;
&lt;p&gt;Diese Methoden sind relativ praktisch beim Zugreifen auf die Antwort nach einer  beendeten Netzwerk-Operation. Wenn das Format falsch ist, liefern die Methoden “nil” zurück. Wenn zum Beispiel versucht wird auf “responseImage” zuzugreifen, obwohl die aktuelle Antwort eine HTML Antwort ist, wird “nil” zurückgeliefert. Die einzige Methode, die garantiert das richtige und erwartete Resultat zurück liefert, ist “responseData”. Die anderen Methoden sollten benutzt werden, wenn der Typ der Antwort bekannt ist. &lt;/p&gt;
&lt;p&gt;Sinnvolle Makros&lt;br /&gt;
Die Makros, “DLog” und “ALog” sind frecherweise von Stackoverflow geklaut und leider kann ich die Quelle nicht mehr finden. Falls du diese Makros geschrieben haben solltest, lass es mich wissen.&lt;/p&gt;
&lt;p&gt;Eine Bemerkung zu GCD&lt;br /&gt;
Ich habe absichtlich GCD nicht verwendet, da Netzwerk Operationen bei Bedarf gestoppt und priorisiert werden müssen. GCD kann dies, obwohl es effektiver als NSOperationQueue ist, nicht. Ich empfehle GCD-basierte Queues nicht für Netzwerk-Operationen zu verwenden.&lt;/p&gt;
&lt;p&gt;Dokumentation&lt;br /&gt;
Die Header-Files sind dokumentiert und ich probiere gerade das “headerdoc” von Apple aus. Währenddessen kannst du ein wenig mit dem Code herumspielen bzw. ihn verwenden (read: Fork).&lt;/p&gt;
&lt;p&gt;Source Code&lt;br /&gt;
Der Source Code für das MKNetworkKit ist zusammen mit einer Demo-Applikation auf Github verfügbar.&lt;br /&gt;
MKNetworkKit bei Github&lt;/p&gt;
&lt;p&gt;Anfragen für neue Funktionen&lt;br /&gt;
Bitte schickt mir keine Email für Funktionen, die ihr gerne in der Zukunft hättet. Der beste Weg ist ein Issue auf Github zu erzeugen.&lt;/p&gt;
&lt;p&gt;Lizenz&lt;br /&gt;
MKNetworkKit ist unter der MIT Lizenz lizensiert.&lt;/p&gt;
&lt;p&gt;Der gesamte Source Code kann unentgeltlich in deiner App genutzt werden, wenn ein Copyright Hinweis in der App angezeigt wird. Eine kleine Erwähnung in den tiefsten Winkeln deiner “About”-Seiten reicht aus.&lt;/p&gt;
&lt;p&gt;Eine Attribution freie Lizenz kann auf Nachfrage stattgegeben werden. Kontaktiert mich unter mknetworkkit@mk.sg&lt;/p&gt;
&lt;p&gt;&lt;map name='google_ad_map_2061_8b86e81420c6776e'&gt;
&lt;area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/2061?pos=0' coords='1,2,367,28' /&gt;
&lt;area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/&gt;&lt;/map&gt;
&lt;img usemap='#google_ad_map_2061_8b86e81420c6776e' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;amp;client=&amp;amp;channel=&amp;amp;output=png&amp;amp;cuid=2061&amp;amp;url= http%3A%2F%2Fblog.mugunthkumar.com%2Fproducts%2Fios-framework-einfuhrung-in-mknetworkkit-german-translation-of-mknetworkkit-documentation%2F' /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href ="http://twitter.com/mugunthkumar"&gt;Follow me &lt;/a&gt; on Twitter&lt;/p&gt;
&lt;div class='yarpp-related-rss yarpp-related-none'&gt;
&lt;p&gt;No related posts.&lt;/p&gt;
&lt;img src='http://yarpp.org/pixels/8b86e81420c6776e456ee5dbf4b38381'/&gt;
&lt;/div&gt;
&lt;img src="http://feeds.feedburner.com/~r/MugunthKumar/~4/FAzucGBfNAQ" height="1" width="1"/&gt;</content><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blog.mugunthkumar.com/products/ios-framework-einfuhrung-in-mknetworkkit-german-translation-of-mknetworkkit-documentation/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">0</slash:comments><feedburner:origLink>http://blog.mugunthkumar.com/products/ios-framework-einfuhrung-in-mknetworkkit-german-translation-of-mknetworkkit-documentation/</feedburner:origLink></entry><entry><title type="text">MKBlockTimer</title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MugunthKumar/~3/eFRlMJY-a_s/" /><category term="Coding" /><category term="ios" /><category term="objective c" /><category term="performance" /><category term="timer" /><author><name>Mugunth Kumar</name></author><updated>2013-04-04T07:11:53-07:00</updated><id>http://blog.mugunthkumar.com/?p=2052</id><summary type="html">Just published a NSObject category, MKBlockTimer. Use this nifty utility to measure the time taken to execute a block of code, without macros. Usage The method is fairly straightforward to use. &amp;#91;self logTimeTakenToRunBlock:^&amp;#123; &amp;#160; // your time consuming piece of code here for&amp;#40;int i = 0 ; i &amp;#38;lt; 1000000000; i ++&amp;#41;; &amp;#160; &amp;#125; withPrefix:@&amp;#34;For [...]&lt;div class='yarpp-related-rss yarpp-related-none'&gt;

No related posts.
&lt;img src='http://yarpp.org/pixels/8b86e81420c6776e456ee5dbf4b38381'/&gt;
&lt;/div&gt;</summary><content type="html">&lt;p&gt;&lt;/p&gt;&lt;p&gt;Just published a NSObject category, MKBlockTimer.&lt;br /&gt;
Use this nifty utility to measure the time taken to execute a block of code, without macros.&lt;/p&gt;
&lt;span id="Usage"&gt;&lt;h2&gt;Usage&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;The method is fairly straightforward to use.&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;  &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;self logTimeTakenToRunBlock&lt;span style="color: #002200;"&gt;:^&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
    &lt;span style="color: #11740a; font-style: italic;"&gt;// your time consuming piece of code here&lt;/span&gt;
    &lt;span style="color: #a61390;"&gt;for&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;int&lt;/span&gt; i &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #2400d9;"&gt;0&lt;/span&gt; ; i &lt;span style="color: #002200;"&gt;&amp;amp;&lt;/span&gt;lt; &lt;span style="color: #2400d9;"&gt;1000000000&lt;/span&gt;; i &lt;span style="color: #002200;"&gt;++&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;;
&amp;nbsp;
  &lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt; withPrefix&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;For Loop&amp;quot;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;When you do this, you should see the following on the console.&lt;/p&gt;
&lt;span id="Output"&gt;&lt;h3&gt;Output&lt;/h3&gt;&lt;/span&gt;
&lt;pre&gt;2013-04-04 22:07:08.966 MKBlockTimerDemo[69436:c07] &lt;strong&gt;For Loop: 1814 ms&lt;/strong&gt;&lt;/pre&gt;
&lt;p&gt;The method logs the time taken to execute the block on the console with a specified prefix. You can pass any string for prefix and use it to identify the block. I&amp;#8217;ve been using this for quite sometime and thought would open source it. I find this method much clearer than manually adding startTimer and endTimer methods and hope it would be useful for you too.&lt;/p&gt;
&lt;span id="Source_Code"&gt;&lt;h2&gt;Source Code&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;The code is available under MIT license at the Github repository &lt;a href="https://github.com/MugunthKumar/MKBlockTimer"&gt;MKBlockTimer&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;#8211;&lt;br /&gt;
Mugunth&lt;/p&gt;
&lt;p&gt;&lt;map name='google_ad_map_2052_8b86e81420c6776e'&gt;
&lt;area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/2052?pos=0' coords='1,2,367,28' /&gt;
&lt;area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/&gt;&lt;/map&gt;
&lt;img usemap='#google_ad_map_2052_8b86e81420c6776e' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;amp;client=&amp;amp;channel=&amp;amp;output=png&amp;amp;cuid=2052&amp;amp;url= http%3A%2F%2Fblog.mugunthkumar.com%2Fcoding%2Fmkblocktimer%2F' /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href ="http://twitter.com/mugunthkumar"&gt;Follow me &lt;/a&gt; on Twitter&lt;/p&gt;
&lt;div class='yarpp-related-rss yarpp-related-none'&gt;
&lt;p&gt;No related posts.&lt;/p&gt;
&lt;img src='http://yarpp.org/pixels/8b86e81420c6776e456ee5dbf4b38381'/&gt;
&lt;/div&gt;
&lt;img src="http://feeds.feedburner.com/~r/MugunthKumar/~4/eFRlMJY-a_s" height="1" width="1"/&gt;</content><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blog.mugunthkumar.com/coding/mkblocktimer/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">1</slash:comments><feedburner:origLink>http://blog.mugunthkumar.com/coding/mkblocktimer/</feedburner:origLink></entry><entry><title type="text">Deploymate – An essential Xcode companion for iOS developers</title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MugunthKumar/~3/arm6DkRWEgQ/" /><category term="Tech" /><category term="deploymate" /><category term="xcode" /><author><name>Mugunth Kumar</name></author><updated>2013-03-14T02:04:58-07:00</updated><id>http://blog.mugunthkumar.com/?p=2040</id><summary type="html">When you write an iOS app, you always use the &amp;#8220;Latest iOS SDK&amp;#8221; as your Base SDK and choose a older iOS version as your deployment target. As on date, you would probably use iOS 6.1.2 as your based SDK and iOS 5.1 as your target. Because your Base SDK is 6.x, you are free [...]&lt;div class='yarpp-related-rss'&gt;

Related posts:&lt;ol&gt;
&lt;li&gt;&lt;a href='http://blog.mugunthkumar.com/tech/rdar-12235700-enable-auto-layout-for-new-nib-files-only-when-deployment-target-supports-it/' rel='bookmark' title='RDAR 12235700: Enable Auto Layout for new nib files only when deployment target supports it'&gt;RDAR 12235700: Enable Auto Layout for new nib files only when deployment target supports it&lt;/a&gt; &lt;small&gt;Submitted this radar to Apple a couple of weeks ago....&lt;/small&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href='http://blog.mugunthkumar.com/tech/windows-store-app-development-for-ios-developers/' rel='bookmark' title='Windows Store App Development for iOS Developers'&gt;Windows Store App Development for iOS Developers&lt;/a&gt; &lt;small&gt;Microsoft has partnered with Big Nerd Ranch to bring iOS...&lt;/small&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;img src='http://yarpp.org/pixels/8b86e81420c6776e456ee5dbf4b38381'/&gt;
&lt;/div&gt;</summary><content type="html">&lt;p&gt;&lt;/p&gt;&lt;p&gt;When you write an iOS app, you always use the &amp;#8220;Latest iOS SDK&amp;#8221; as your Base SDK and choose a older iOS version as your deployment target. As on date, you would probably use iOS 6.1.2 as your based SDK and iOS 5.1 as your target.&lt;/p&gt;
&lt;p&gt;Because your Base SDK is 6.x, you are free to use APIs and frameworks that were introduced in iOS 6. However, its your responsibility as a developer to ensure that you either fallback gracefully on older versions of iOS either by providing alternatives or disabling the feature altogether.&lt;/p&gt;
&lt;p&gt;For example, if the feature that you are implementing is &amp;#8220;Sharing on Facebook&amp;#8221;, you should be using the built in Facebook sharing (SLComposeViewController) on iOS 6 and fallback gracefully by sharing using the Facebook&amp;#8217;s official SDK for iOS 5 devices.&lt;/p&gt;
&lt;p&gt;Failing to do this will result in your app crashing on a older operating system.&lt;/p&gt;
&lt;span id="Preventing_crashes"&gt;&lt;h2&gt;Preventing crashes&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;When your deployment target is not the same as your Base SDK, you need to ensure three things to prevent your app from crashing. &lt;/p&gt;
&lt;p&gt;1. Check if every framework you are linking against is available in all versions of iOS you are deploying to.&lt;/p&gt;
&lt;p&gt;2. Check if every class you are using is available in all versions of iOS you are deploying to,&lt;/p&gt;
&lt;p&gt;3. Check if every function you are using is available in all versions of iOS you are deploying to.&lt;/p&gt;
&lt;span id="Framework_Availability"&gt;&lt;h3&gt;Framework Availability&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;See if all the frameworks you are linking against are available on all operating systems you are deploying to. If a specific framework is not available in  For example, if you are linking against Social.Framework introduced in iOS 6, on an app that is deployed on iOS 5, your app will crash immediately at start up. The way to fix this crash is to weak-link the framework.&lt;/p&gt;
&lt;p&gt;Fairly straight forward. You might be linking against a fairly limited number of frameworks and it&amp;#8217;s easy to check them.&lt;/p&gt;
&lt;span id="Class_Availability"&gt;&lt;h3&gt;Class Availability&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;Sometimes an existing framework like UIKit or Foundation will have additional classes added. UICollectionView is a good example. If you use UICollectionView, you should ensure that, you either hide those UI on older devices, or using alternative UI on older devices by conditionally checking for availability of class.&lt;/p&gt;
&lt;p&gt;You do that by&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #a61390;"&gt;if&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;UICollectionView class&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
 &lt;span style="color: #11740a; font-style: italic;"&gt;// iOS 6 specific code&lt;/span&gt;
&lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt; &lt;span style="color: #a61390;"&gt;else&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
 &lt;span style="color: #11740a; font-style: italic;"&gt;// iOS 5 specific code&lt;/span&gt;
&lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Slightly tricky.&lt;/p&gt;
&lt;span id="Method_Availability"&gt;&lt;h3&gt;Method Availability&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;Sometimes an existing class will have new methods added. An example would be &lt;em&gt;registerClass:forCellReuseIdentifier:&lt;/em&gt; in UITableView. This method is available only from iOS 6. You normally check for method availability using respondsToSelector and use it if the method is present.&lt;/p&gt;
&lt;p&gt;Keeping track of method availability is arguably harder than the other two.&lt;/p&gt;
&lt;span id="Meet_Deploymate"&gt;&lt;h2&gt;Meet Deploymate&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;Deploymate is a third party solution to free you from worrying about the last kind of crash, method availability check. All you need to do is to open your project in Deploymate and &amp;#8220;Analyze&amp;#8221; it. Deploymate will report if you are using any APIs that are not available in your deployment target operating system version.&lt;/p&gt;
&lt;p&gt;By default Deploymate runs your code against the &amp;#8220;Deployment Target&amp;#8221; you set in your project. You can even change this setting without changing your project setting and &amp;#8220;Analyze&amp;#8221; again. So, even if your project&amp;#8217;s deployment target is 5.1, you can try if it runs on iOS 5.0 using Deploymate and even change your project to deploy to iOS 5 devices.&lt;/p&gt;
&lt;span id="Features_missing"&gt;&lt;h2&gt;Features missing&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;While the guys behind Deploymate has indeed done a great job, (in fact Deploymate is something that I would expect Apple to do) Deploymate, as on date doesn&amp;#8217;t track wrong class usage or missed weak-linking on frameworks. I seriously wish those features are their highest priority. Nevertheless, the app is kind of complete now.&lt;/p&gt;
&lt;span id="Download"&gt;&lt;h2&gt;Download&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;You can read more about Deploymate on their website &lt;a href="http://www.deploymateapp.com"&gt;here&lt;/a&gt;. The app is on sale for $9.99. I just bought it and this is probably the best $10 you would have ever spent on an app. Get it now.&lt;/p&gt;
&lt;p&gt;&amp;#8211;&lt;/p&gt;
&lt;p&gt;Mugunth&lt;/p&gt;
&lt;p&gt;&lt;map name='google_ad_map_2040_8b86e81420c6776e'&gt;
&lt;area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/2040?pos=0' coords='1,2,367,28' /&gt;
&lt;area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/&gt;&lt;/map&gt;
&lt;img usemap='#google_ad_map_2040_8b86e81420c6776e' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;amp;client=&amp;amp;channel=&amp;amp;output=png&amp;amp;cuid=2040&amp;amp;url= http%3A%2F%2Fblog.mugunthkumar.com%2Ftech%2Fdeploymate-an-essential-xcode-companion-for-ios-developers%2F' /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href ="http://twitter.com/mugunthkumar"&gt;Follow me &lt;/a&gt; on Twitter&lt;/p&gt;
&lt;div class='yarpp-related-rss'&gt;
&lt;p&gt;Related posts:&lt;ol&gt;
&lt;li&gt;&lt;a href='http://blog.mugunthkumar.com/tech/rdar-12235700-enable-auto-layout-for-new-nib-files-only-when-deployment-target-supports-it/' rel='bookmark' title='RDAR 12235700: Enable Auto Layout for new nib files only when deployment target supports it'&gt;RDAR 12235700: Enable Auto Layout for new nib files only when deployment target supports it&lt;/a&gt; &lt;small&gt;Submitted this radar to Apple a couple of weeks ago....&lt;/small&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href='http://blog.mugunthkumar.com/tech/windows-store-app-development-for-ios-developers/' rel='bookmark' title='Windows Store App Development for iOS Developers'&gt;Windows Store App Development for iOS Developers&lt;/a&gt; &lt;small&gt;Microsoft has partnered with Big Nerd Ranch to bring iOS...&lt;/small&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/p&gt;
&lt;img src='http://yarpp.org/pixels/8b86e81420c6776e456ee5dbf4b38381'/&gt;
&lt;/div&gt;
&lt;img src="http://feeds.feedburner.com/~r/MugunthKumar/~4/arm6DkRWEgQ" height="1" width="1"/&gt;</content><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blog.mugunthkumar.com/tech/deploymate-an-essential-xcode-companion-for-ios-developers/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">3</slash:comments><feedburner:origLink>http://blog.mugunthkumar.com/tech/deploymate-an-essential-xcode-companion-for-ios-developers/</feedburner:origLink></entry><entry><title type="text">Why you shouldn’t hire a iOS developer based on his portfolio</title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MugunthKumar/~3/y1upXt-YLeI/" /><category term="Articles" /><category term="hiring" /><category term="rant" /><author><name>Mugunth Kumar</name></author><updated>2013-02-24T08:30:48-08:00</updated><id>http://blog.mugunthkumar.com/?p=2034</id><summary type="html">Well, this is not a tech post. Shoo… developers… I&amp;#8217;m not sure if this is a &amp;#8220;Singaporean&amp;#8221; thing or applies globally. Some people who are in charge of hiring has no clue how to get a good developer. So the first question they ask is for your &amp;#8220;portfolio&amp;#8220;. I really don&amp;#8217;t understand how a iOS [...]&lt;div class='yarpp-related-rss yarpp-related-none'&gt;

No related posts.
&lt;img src='http://yarpp.org/pixels/8b86e81420c6776e456ee5dbf4b38381'/&gt;
&lt;/div&gt;</summary><content type="html">&lt;p&gt;&lt;/p&gt;&lt;p&gt;Well, this is not a tech post. Shoo… developers…&lt;/p&gt;
&lt;p&gt;I&amp;#8217;m not sure if this is a &amp;#8220;Singaporean&amp;#8221; thing or applies globally. Some people who are in charge of hiring has no clue how to get a good developer. So the first question they ask is for your &amp;#8220;&lt;em&gt;&lt;strong&gt;portfolio&lt;/strong&gt;&lt;/em&gt;&amp;#8220;. I really don&amp;#8217;t understand how a iOS developer&amp;#8217;s skill can be measured based on his application portfolio. A good looking app doesn&amp;#8217;t correlate to a well written code. Back in the olden days of Web 2.0, asking for a portfolio means, you can have a look at the completed website AND the code (Javascript + CSS). Just because you hired people looking for their portfolios in the past doesn&amp;#8217;t mean you should do that now.&lt;/p&gt;
&lt;p&gt;Instead, ask the prospective hire for his open source contributions. Mine is &lt;a href="http://github.com/MugunthKumar/"&gt;here&lt;/a&gt;. If you aren&amp;#8217;t too conversant looking at code, ask for client references. Turns out that, most developers can do this. (As developers you can ask your client before giving out their names as references. Believe me, almost all clients are more than willing to do so.)&lt;/p&gt;
&lt;p&gt;App portfolios aren&amp;#8217;t a great way to judge a iOS developer (or any closed source developer). Think again, have you ever hired a backend developer (PHP/Ruby/ASP.NET/Java) by looking at the website he built? Hiring a iOS developer is very similar to hiring a backend developer. App portfolios are good for design agencies and makes sense when you are hiring a designer (or outsourcing your complete app to an agency).&lt;/p&gt;
&lt;p&gt;Stop asking for app portfolios. Look at the prospective developers&amp;#8217; Github contributions or ask for client references.&lt;/p&gt;
&lt;p&gt;&amp;#8211;&lt;br /&gt;
Mugunth&lt;/p&gt;
&lt;p&gt;&lt;map name='google_ad_map_2034_8b86e81420c6776e'&gt;
&lt;area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/2034?pos=0' coords='1,2,367,28' /&gt;
&lt;area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/&gt;&lt;/map&gt;
&lt;img usemap='#google_ad_map_2034_8b86e81420c6776e' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;amp;client=&amp;amp;channel=&amp;amp;output=png&amp;amp;cuid=2034&amp;amp;url= http%3A%2F%2Fblog.mugunthkumar.com%2Farticles%2Fwhy-you-shouldnt-hire-a-ios-developer-based-on-his-portfolio%2F' /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href ="http://twitter.com/mugunthkumar"&gt;Follow me &lt;/a&gt; on Twitter&lt;/p&gt;
&lt;div class='yarpp-related-rss yarpp-related-none'&gt;
&lt;p&gt;No related posts.&lt;/p&gt;
&lt;img src='http://yarpp.org/pixels/8b86e81420c6776e456ee5dbf4b38381'/&gt;
&lt;/div&gt;
&lt;img src="http://feeds.feedburner.com/~r/MugunthKumar/~4/y1upXt-YLeI" height="1" width="1"/&gt;</content><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blog.mugunthkumar.com/articles/why-you-shouldnt-hire-a-ios-developer-based-on-his-portfolio/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">6</slash:comments><feedburner:origLink>http://blog.mugunthkumar.com/articles/why-you-shouldnt-hire-a-ios-developer-based-on-his-portfolio/</feedburner:origLink></entry><entry><title type="text">iOS programming architecture and design guidelines</title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MugunthKumar/~3/V33plCHBYCo/" /><category term="Articles" /><category term="architecture" /><category term="design pattern" /><category term="ios" /><author><name>Mugunth Kumar</name></author><updated>2013-02-19T21:07:50-08:00</updated><id>http://blog.mugunthkumar.com/?p=2023</id><summary type="html">A good programmer gets the job done. A great programmer gets the job done, the right way. I&amp;#8217;ve been a programmer for more than a decade now and been writing Objective-C code for almost half a decade. Some of the coding guidelines I follow have been immensely useful to me and I guess will be [...]&lt;div class='yarpp-related-rss yarpp-related-none'&gt;

No related posts.
&lt;img src='http://yarpp.org/pixels/8b86e81420c6776e456ee5dbf4b38381'/&gt;
&lt;/div&gt;</summary><content type="html">&lt;p&gt;&lt;/p&gt;&lt;p&gt;A good programmer gets the job done. A great programmer gets the job done, the right way. I&amp;#8217;ve been a programmer for more than a decade now and been writing Objective-C code for almost half a decade. Some of the coding guidelines I follow have been immensely useful to me and I guess will be useful to you too.&lt;/p&gt;
&lt;p&gt;Before that, a brief background. I started my career doing Win 32 SDK/MFC programming. Delved a bit into Windows Device Driver Kit (DDK) and into C#.NET and Java. Most of my life was into Object-oriented programming languages that are more strongly (and statically) typed than Javascript or PHP (and during those good old days, neither Javascript, nor PHP were Object oriented).&lt;/p&gt;
&lt;p&gt;When a great programmer writes code in a given language, he follows the principles in that language instead of enforcing principles from his favourite language. In short, don&amp;#8217;t write &amp;#8220;Java&amp;#8221; like code in Objective-C and Objective-C like code in Javascript. For most of us, Objective-C was not our first programming language and I believe, most of today&amp;#8217;s Objective-C programmers are like me. A succinct explanation would help you understand the differences and make you a better Objective-C programmer.&lt;/p&gt;
&lt;span id="Types_in_Objective-C"&gt;&lt;h2&gt;Types in Objective-C&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;First is typing. Typing can be static or dynamic depending on &lt;em&gt;when&lt;/em&gt; type safety is enforced by the language/compiler. Typing can be strong or weak depending on &lt;em&gt;if&lt;/em&gt; the compiler would allow implicit type conversions. Some languages implicitly convert strings to integers and vice versa. so 1 + 2 is 3 and &amp;#8220;1&amp;#8243; + &amp;#8220;2&amp;#8243; is &amp;#8220;12&amp;#8243; and 1 + &amp;#8220;2a&amp;#8221; is &amp;#8220;12a&amp;#8221;.&lt;/p&gt;
&lt;p&gt;Objective-C is somewhere in between a strongly typed language like Java/C# and a weakly typed language like Javascript/PHP. Most of the type checking is implemented at runtime and Objective-C is a dynamically typed language.&lt;/p&gt;
&lt;p&gt;For example,&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;var $i &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #2400d9;"&gt;1&lt;/span&gt;;
$i &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #bf1d1a;"&gt;&amp;quot;Hello World&amp;quot;&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;is perfectly valid is PHP (or Javascript), It&amp;#8217;s illegal in a strongly typed language like C#/Java.&lt;br /&gt;
Objective-C, as I said before, is somewhere in between. The compiler will warn you that you are trying to assign a incompatible pointer type.&lt;/p&gt;
&lt;p&gt;It enforces type at compile time (at least warns) on most classes, but not collections. That means, in Objective-C, you will get a warning when you assign a &lt;em&gt;NSString&lt;/em&gt; to a &lt;em&gt;UIViewController&lt;/em&gt; object, but it&amp;#8217;s perfectly fine to add a &lt;em&gt;NSString&lt;/em&gt; and a UIViewController object into the same &lt;em&gt;NSMutableArray&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;However, you are free to override the warning by simply using a typecast.&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;  &lt;span style="color: #400080;"&gt;NSArray&lt;/span&gt; &lt;span style="color: #002200;"&gt;*&lt;/span&gt;a;
  a &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #400080;"&gt;NSArray&lt;/span&gt;&lt;span style="color: #002200;"&gt;*&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Not that I&amp;#8217;m advocating typecasts, get the point that, Objective-C is weakly typed, but not as weakly typed as Javascript or PHP. Java/C# on the other hand are strongly typed less dynamic than Objective-C. In Java, adding a non-compliant object to a collection class will be caught by the compiler if the compiler can reliably infer the type of the added object or the run time will throw a &lt;em&gt;ClassCastException&lt;/em&gt;. No such thing in Objective-C.&lt;/p&gt;
&lt;p&gt;When it comes to programming, there is no one best language. As a great programmer, you should &lt;strong&gt;NOT&lt;/strong&gt; be a fan of a given type system. Embrace strong+static typing when you code in Java and appreciate the beauty of semi-strong + dynamic typing when you write Objective-C. Objective-C (and most C based languages) were invented for writing high performance software and the onus of type safety or checking the bounds of array indices is on you, the programmer and not the compiler.&lt;/p&gt;
&lt;p&gt;So there comes our first rule. Never write Objective-C code that reads like code from a strongly typed language.&lt;/p&gt;
&lt;span id="Naming_conventions"&gt;&lt;h2&gt;Naming conventions&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;Objective-C method names are verbose. Yes, you are reading it right. Objective-C is a verbose language. Method names are verbose and less imperative than C/C++ or even Java. For example,&lt;/p&gt;
&lt;p&gt;-getCacheDirectory; should probably be named as -cacheDirectory.&lt;/p&gt;
&lt;p&gt;-convertToJson should probably be named as -jsonValue&lt;/p&gt;
&lt;p&gt;Tone down the level of imperativeness in your code. Embrace verbosity. While your favourite language, Ruby is succinct, Objective-C isn&amp;#8217;t. Ruby is succinct, probably because most of the typing is done using a text editor that doesn&amp;#8217;t do intelligent auto completes. Writing succinct method names or writing macros to introduce succinctness in your Objective-C code will only confuse other Objective-C programmers who are not familiar with your &amp;#8220;other&amp;#8221; programming language.&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;When in Rome, be a Roman. While writing Objective-C code, be an Objective-C programmer.&lt;/p&gt;&lt;/blockquote&gt;
&lt;span id="Subclassing"&gt;&lt;h2&gt;Subclassing&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;In almost any programming language, subclassing a framework provided class is perfectly allowed. But not in Objective-C. Most of the commonly used classes like NSArray, NSSet, NSDictionary are essentially clusters. Subclassing them is not advised unless you are planning to forward invocations or by implementing all of the primitive methods necessary.&lt;/p&gt;
&lt;p&gt;In most traditional programming languages, you subclass a foundation class (like for instance, a NSArray) to either provide additional methods or to override existing methods or to customise appearance of a UI element. In Objective-C, you provided additional methods using a category extension. You override SDK provided implementation by swizzling the method and you use the appearance proxy protocol to customise appearance of a UI element.&lt;/p&gt;
&lt;p&gt;Having said that, there are some classes that you commonly override. UIViewController, UITableViewController, UIControl are a few to name. Subclassing UIViewController is probably the best thing you can do to your app. Adding common functionalities becomes just so easy. In every app I do, I have a UIViewController subclass that has a bunch of common functionalities. All other view controllers that I use in the app inherit from this special view controller.&lt;/p&gt;
&lt;p&gt;So, instead of&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #a61390;"&gt;@interface&lt;/span&gt; MyAppFeaturedYouTubeVideosViewController &lt;span style="color: #002200;"&gt;:&lt;/span&gt; UIViewController&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;it would be&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #a61390;"&gt;@interface&lt;/span&gt; MyAppFeaturedYouTubeVideosFeaturedViewController &lt;span style="color: #002200;"&gt;:&lt;/span&gt; MyAppViewController
&lt;span style="color: #a61390;"&gt;@interface&lt;/span&gt; MyAppViewController &lt;span style="color: #002200;"&gt;:&lt;/span&gt; UIViewController&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;This common base class can be used to add common functionalities in future. I usually have the following methods in this super class.&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #002200;"&gt;-&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;UIView&lt;span style="color: #002200;"&gt;*&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; errorView;
&lt;span style="color: #002200;"&gt;-&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;UIView&lt;span style="color: #002200;"&gt;*&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; loadingView;
&lt;span style="color: #002200;"&gt;-&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;void&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; showLoadingAnimated&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;BOOL&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; animated;
&lt;span style="color: #002200;"&gt;-&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;void&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; hideLoadingViewAnimated&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;BOOL&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; animated;
&lt;span style="color: #002200;"&gt;-&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;void&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; showErrorViewAnimated&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;BOOL&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; animated;
&lt;span style="color: #002200;"&gt;-&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;void&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; hideErrorViewAnimated&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;BOOL&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; animated;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Implementation details below.&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #002200;"&gt;-&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;UIView&lt;span style="color: #002200;"&gt;*&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; errorView &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
  &lt;span style="color: #a61390;"&gt;return&lt;/span&gt; &lt;span style="color: #a61390;"&gt;nil&lt;/span&gt;;
&lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style="color: #002200;"&gt;-&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;UIView&lt;span style="color: #002200;"&gt;*&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; loadingView &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
  &lt;span style="color: #a61390;"&gt;return&lt;/span&gt; &lt;span style="color: #a61390;"&gt;nil&lt;/span&gt;;
&lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style="color: #002200;"&gt;-&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;void&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; showLoadingAnimated&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;BOOL&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; animated &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
  UIView &lt;span style="color: #002200;"&gt;*&lt;/span&gt;loadingView &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;self loadingView&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
  loadingView.alpha &lt;span style="color: #002200;"&gt;=&lt;/span&gt; 0.0f;
  &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;self.view addSubview&lt;span style="color: #002200;"&gt;:&lt;/span&gt;loadingView&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
  &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;self.view bringSubviewToFront&lt;span style="color: #002200;"&gt;:&lt;/span&gt;loadingView&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
&amp;nbsp;
  &lt;span style="color: #a61390;"&gt;double&lt;/span&gt; duration &lt;span style="color: #002200;"&gt;=&lt;/span&gt; animated ? 0.4f&lt;span style="color: #002200;"&gt;:&lt;/span&gt;0.0f;
  &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;UIView animateWithDuration&lt;span style="color: #002200;"&gt;:&lt;/span&gt;duration animations&lt;span style="color: #002200;"&gt;:^&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
    loadingView.alpha &lt;span style="color: #002200;"&gt;=&lt;/span&gt; 1.0f;
  &lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
&lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style="color: #002200;"&gt;-&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;void&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; hideLoadingViewAnimated&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;BOOL&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; animated &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
  UIView &lt;span style="color: #002200;"&gt;*&lt;/span&gt;loadingView &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;self loadingView&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
&amp;nbsp;
  &lt;span style="color: #a61390;"&gt;double&lt;/span&gt; duration &lt;span style="color: #002200;"&gt;=&lt;/span&gt; animated ? 0.4f&lt;span style="color: #002200;"&gt;:&lt;/span&gt;0.0f;
  &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;UIView animateWithDuration&lt;span style="color: #002200;"&gt;:&lt;/span&gt;duration animations&lt;span style="color: #002200;"&gt;:^&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
    loadingView.alpha &lt;span style="color: #002200;"&gt;=&lt;/span&gt; 0.0f;
  &lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt; completion&lt;span style="color: #002200;"&gt;:^&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;BOOL&lt;/span&gt; finished&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
    &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;loadingView removeFromSuperview&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
  &lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
&lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style="color: #002200;"&gt;-&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;void&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; showErrorViewAnimated&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;BOOL&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; animated &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
  UIView &lt;span style="color: #002200;"&gt;*&lt;/span&gt;errorView &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;self errorView&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
  errorView.alpha &lt;span style="color: #002200;"&gt;=&lt;/span&gt; 0.0f;
  &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;self.view addSubview&lt;span style="color: #002200;"&gt;:&lt;/span&gt;errorView&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
  &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;self.view bringSubviewToFront&lt;span style="color: #002200;"&gt;:&lt;/span&gt;errorView&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
&amp;nbsp;
  &lt;span style="color: #a61390;"&gt;double&lt;/span&gt; duration &lt;span style="color: #002200;"&gt;=&lt;/span&gt; animated ? 0.4f&lt;span style="color: #002200;"&gt;:&lt;/span&gt;0.0f;
  &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;UIView animateWithDuration&lt;span style="color: #002200;"&gt;:&lt;/span&gt;duration animations&lt;span style="color: #002200;"&gt;:^&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
    errorView.alpha &lt;span style="color: #002200;"&gt;=&lt;/span&gt; 1.0f;
  &lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
&lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style="color: #002200;"&gt;-&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;void&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; hideErrorViewAnimated&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;BOOL&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; animated &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
  UIView &lt;span style="color: #002200;"&gt;*&lt;/span&gt;errorView &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;self errorView&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
&amp;nbsp;
  &lt;span style="color: #a61390;"&gt;double&lt;/span&gt; duration &lt;span style="color: #002200;"&gt;=&lt;/span&gt; animated ? 0.4f&lt;span style="color: #002200;"&gt;:&lt;/span&gt;0.0f;
  &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;UIView animateWithDuration&lt;span style="color: #002200;"&gt;:&lt;/span&gt;duration animations&lt;span style="color: #002200;"&gt;:^&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
    errorView.alpha &lt;span style="color: #002200;"&gt;=&lt;/span&gt; 0.0f;
  &lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt; completion&lt;span style="color: #002200;"&gt;:^&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;BOOL&lt;/span&gt; finished&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
    &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;errorView removeFromSuperview&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
  &lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
&lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Now, in my application&amp;#8217;s View Controller subclass, I can easily change the view to a &amp;#8220;loading&amp;#8221; state or &amp;#8220;error&amp;#8221; state just by calling one of the following methods. Additionally, view controllers can override, &lt;em&gt;-errorView&lt;/em&gt; and &lt;em&gt;-loadingView&lt;/em&gt; methods to provide their own custom error and loading views.&lt;/p&gt;
&lt;p&gt;You can even override viewDidLoad in the super class to change the look and feel of the all the views in your app. For example, adding a background pattern to your views or changing the background colour of all your views.&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #002200;"&gt;-&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;void&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;viewDidLoad
&lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
  &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;super viewDidLoad&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
  self.view.backgroundColor &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;UIColor appOffWhiteColor&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;; &lt;span style="color: #11740a; font-style: italic;"&gt;// changes all my views to &amp;quot;off-white&amp;quot;&lt;/span&gt;
&lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;

&lt;span id="UI_Customisation"&gt;&lt;h2&gt;UI Customisation&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;UI Customisation can be classified broadly into two. Writing custom controls. Skinning/theming the app. The former is what makes the app stand out from the crowd. The latter is what most apps require. I recommend writing a category extension on UIFont and UIColor to provide custom fonts and colours for your app.&lt;/p&gt;
&lt;p&gt;For example, add methods like&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #002200;"&gt;+&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;UIFont&lt;span style="color: #002200;"&gt;*&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; appFontOfSize&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;CGFloat&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; pointSize &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
  &lt;span style="color: #a61390;"&gt;return&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;UIFont fontWithName&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;MyriadPro-Regular&amp;quot;&lt;/span&gt; size&lt;span style="color: #002200;"&gt;:&lt;/span&gt;pointSize&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
&lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style="color: #002200;"&gt;+&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;UIFont&lt;span style="color: #002200;"&gt;*&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; boldAppFontOfSize&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;CGFloat&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; pointSize &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
  &lt;span style="color: #a61390;"&gt;return&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;UIFont fontWithName&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;MyriadPro-Black&amp;quot;&lt;/span&gt; size&lt;span style="color: #002200;"&gt;:&lt;/span&gt;pointSize&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
&lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;to a UIFont category and use [UIFont appFontOfSize:13] to create a MyriadPro-Regular font. This way, you can easily switch to a different font later when your designer decides so.&lt;/p&gt;
&lt;p&gt;The same design pattern can be applied for providing custom colours. Add a category on UIColor and write methods like the following&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #6e371a;"&gt;#define GREY(color) [UIColor colorWithRed:color/255.0 green:color/255.0 blue:color/255.0 alpha:1]&lt;/span&gt;
&amp;nbsp;
&lt;span style="color: #002200;"&gt;+&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;UIColor&lt;span style="color: #002200;"&gt;*&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; appBackgroundColor &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
  &lt;span style="color: #a61390;"&gt;return&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;UIColor colorWithPatternImage&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;UIImage imageNamed&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;BGPattern&amp;quot;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
&lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style="color: #002200;"&gt;+&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;UIColor&lt;span style="color: #002200;"&gt;*&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; appBlack1Color &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
  &lt;span style="color: #a61390;"&gt;return&lt;/span&gt; GREY&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #2400d9;"&gt;38&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;;
&lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style="color: #002200;"&gt;+&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;UIColor&lt;span style="color: #002200;"&gt;*&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; appOffWhiteColor &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
  &lt;span style="color: #a61390;"&gt;return&lt;/span&gt; GREY&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #2400d9;"&gt;234&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;;
&lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;For heavens&amp;#8217; sake, don&amp;#8217;t use Interface Builder for choosing a colour.&lt;/p&gt;
&lt;span id="Subclassing_UILabels"&gt;&lt;h2&gt;Subclassing UILabels&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;There is one other school of thought where developers subclass UILabel, UITextField, UITextView and set the font and colour in the initWithFrame and initWithCoder methods. The following explains this technique.&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #a61390;"&gt;@implementation&lt;/span&gt; AppPrefixLabel
&amp;nbsp;
&lt;span style="color: #002200;"&gt;-&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;void&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; setup &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
  self.font &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;UIFont fontWithName&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;SourceSansPro-Semibold&amp;quot;&lt;/span&gt; size&lt;span style="color: #002200;"&gt;:&lt;/span&gt;self.font.pointSize&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
  self.textColor &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;UIColor redColor&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
&lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style="color: #002200;"&gt;-&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;id&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; initWithFrame&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;CGRect&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;frame &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
  &lt;span style="color: #a61390;"&gt;if&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;self &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;super initWithFrame&lt;span style="color: #002200;"&gt;:&lt;/span&gt;frame&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
    &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;self setup&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
  &lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
  &lt;span style="color: #a61390;"&gt;return&lt;/span&gt; self;
&lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;
&lt;span style="color: #002200;"&gt;-&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;id&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; initWithCoder&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #400080;"&gt;NSCoder&lt;/span&gt; &lt;span style="color: #002200;"&gt;*&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;aDecoder &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
  &lt;span style="color: #a61390;"&gt;if&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;self &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;super initWithCoder&lt;span style="color: #002200;"&gt;:&lt;/span&gt;aDecoder&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
    &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;self setup&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
  &lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
  &lt;span style="color: #a61390;"&gt;return&lt;/span&gt; self;
&lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style="color: #a61390;"&gt;@end&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;This technique allows developers to customise appearance of labels and other UIKit elements from Interface Builder. Drag a UILabel to your view and change the class of the label to your custom class, and boom! your fonts and colours are instantly applied without you having to write additional code.&lt;/p&gt;
&lt;p&gt;While this technique works for most part, it becomes troublesome when your application supports custom themes and users can change themes from, say, a settings screen.&lt;/p&gt;
&lt;p&gt;initWithFrame: and initWithCoder: are creation methods that are called once when the UI element is created and changing the font &lt;strong&gt;&lt;em&gt;after&lt;/em&gt;&lt;/strong&gt; it is created requires a bunch of boiler plate code. So, if your app supports themes, create a theme manager singleton that &amp;#8220;provides&amp;#8221; themes and colours for the entire project.&lt;/p&gt;
&lt;p&gt;If you use the first method that I explained, your UIFont category extension methods will now be implemented as&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #002200;"&gt;+&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;UIFont&lt;span style="color: #002200;"&gt;*&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; appFontOfSize&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;CGFloat&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; pointSize &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
  &lt;span style="color: #400080;"&gt;NSString&lt;/span&gt; &lt;span style="color: #002200;"&gt;*&lt;/span&gt;currentFontName &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;ThemeProvider sharedInstance&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt; currentFontName&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
  &lt;span style="color: #a61390;"&gt;return&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;UIFont fontWithName&lt;span style="color: #002200;"&gt;:&lt;/span&gt;currentFontName size&lt;span style="color: #002200;"&gt;:&lt;/span&gt;pointSize&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
&lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Same applies to UIColor category extension methods as well. There is no right or wrong ways to do this. Both methods are perfectly fine and I&amp;#8217;ll leave it to you to figure out which works best for your app.&lt;/p&gt;
&lt;p&gt;Following basic design patterns I explained here can make your iOS project look clean like a well written JS/CSS. Try it in your next app and let me know!&lt;/p&gt;
&lt;p&gt;&amp;#8211;&lt;br /&gt;
Mugunth&lt;/p&gt;
&lt;p&gt;&lt;map name='google_ad_map_2023_8b86e81420c6776e'&gt;
&lt;area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/2023?pos=0' coords='1,2,367,28' /&gt;
&lt;area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/&gt;&lt;/map&gt;
&lt;img usemap='#google_ad_map_2023_8b86e81420c6776e' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;amp;client=&amp;amp;channel=&amp;amp;output=png&amp;amp;cuid=2023&amp;amp;url= http%3A%2F%2Fblog.mugunthkumar.com%2Farticles%2Fios-programming-architecture-and-design-guidelines%2F' /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href ="http://twitter.com/mugunthkumar"&gt;Follow me &lt;/a&gt; on Twitter&lt;/p&gt;
&lt;div class='yarpp-related-rss yarpp-related-none'&gt;
&lt;p&gt;No related posts.&lt;/p&gt;
&lt;img src='http://yarpp.org/pixels/8b86e81420c6776e456ee5dbf4b38381'/&gt;
&lt;/div&gt;
&lt;img src="http://feeds.feedburner.com/~r/MugunthKumar/~4/V33plCHBYCo" height="1" width="1"/&gt;</content><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blog.mugunthkumar.com/articles/ios-programming-architecture-and-design-guidelines/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">3</slash:comments><feedburner:origLink>http://blog.mugunthkumar.com/articles/ios-programming-architecture-and-design-guidelines/</feedburner:origLink></entry><entry><title type="text">Windows Store App Development for iOS Developers</title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MugunthKumar/~3/kE2qU1doX3I/" /><category term="Tech" /><category term="ios" /><category term="online" /><category term="training" /><category term="windows phone" /><author><name>Mugunth Kumar</name></author><updated>2012-12-04T19:32:53-08:00</updated><id>http://blog.mugunthkumar.com/?p=2020</id><summary type="html">Microsoft has partnered with Big Nerd Ranch to bring iOS developers a free two day training designed to jumpstart Windows Store development. The training is a two day event covering the basics, introduction to the platform, design differences between iOS and Windows 8 to Maps, Skydrive and Microsoft account integration. The training happens in San [...]&lt;div class='yarpp-related-rss'&gt;

Related posts:&lt;ol&gt;
&lt;li&gt;&lt;a href='http://blog.mugunthkumar.com/tech/ios-programming-training-courses-in-singapore/' rel='bookmark' title='iOS Programming training courses in Singapore'&gt;iOS Programming training courses in Singapore&lt;/a&gt; &lt;small&gt;After my book got pretty good reviews, I&amp;#8217;ve been approached...&lt;/small&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;img src='http://yarpp.org/pixels/8b86e81420c6776e456ee5dbf4b38381'/&gt;
&lt;/div&gt;</summary><content type="html">&lt;p&gt;&lt;/p&gt;&lt;p&gt;Microsoft has partnered with &lt;a href="http://www.bignerdranch.com"&gt;Big Nerd Ranch&lt;/a&gt; to bring iOS developers a free two day training designed to jumpstart Windows Store development. The training is a two day event covering the basics, introduction to the platform, design differences between iOS and Windows 8 to Maps, Skydrive and Microsoft account integration. &lt;/p&gt;
&lt;p&gt;The training happens in San Francisco. But, unlike most others that are free only for developers in San Francisco, what interests me about the event is that, it will be live streamed and anyone from any part of the world can watch the complete event. If you are in San Francisco, you can just walk down to their office to attend the training in person.&lt;/p&gt;
&lt;span id="Timings"&gt;&lt;h3&gt;Timings&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;The training starts next week, December 13th 9 AM to December 14th 5 PM Pacific time. Around the world, the timings would be&lt;/p&gt;
&lt;p&gt;06:00AM &amp;#8211; Hawaii&lt;/p&gt;
&lt;p&gt;08:00AM &amp;#8211; Alaska&lt;/p&gt;
&lt;p&gt;09:00AM &amp;#8211; Pacific&lt;/p&gt;
&lt;p&gt;10:00AM &amp;#8211; Mountain&lt;/p&gt;
&lt;p&gt;11:00PM &amp;#8211; Central&lt;/p&gt;
&lt;p&gt;12:00PM &amp;#8211; Eastern&lt;/p&gt;
&lt;p&gt;01:00PM &amp;#8211; São Paulo&lt;/p&gt;
&lt;p&gt;05:00PM &amp;#8211; London&lt;/p&gt;
&lt;p&gt;06:00PM &amp;#8211; Paris&lt;/p&gt;
&lt;p&gt;08:00PM &amp;#8211; Moscow&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;01:00AM &amp;#8211; Singapore (the next day)&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;02:00AM &amp;#8211; Tokyo (the next day)&lt;/p&gt;
&lt;p&gt;03:00AM &amp;#8211; Sydney (the next day)&lt;/p&gt;
&lt;span id="Trainers"&gt;&lt;h3&gt;Trainers&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;The trainers for the course will be &lt;a href="https://twitter.com/AaronHillegass"&gt;Aaron Hillegass&lt;/a&gt; and &lt;a href="https://twitter.com/jaimerodriguez"&gt;Jaime Rodriguez&lt;/a&gt;.&lt;/p&gt;
&lt;span id="Registration"&gt;&lt;h3&gt;Registration&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;Register for the event &lt;a href="https://msevents.microsoft.com/cui/EventDetail.aspx?culture=en-US&amp;#038;EventID=1032536068&amp;#038;IO=RvvJnnxnVDMJUriUHWavUw%3d%3d"&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I registered, but I might be skipping the first few as it would early morning 1AM for me. Overall, I&amp;#8217;m excited about Big Nerd Ranch&amp;#8217;s collaboration and see how the Windows Phone platform would evolve.&lt;/p&gt;
&lt;p&gt;Your should register too.&lt;/p&gt;
&lt;p&gt;&amp;#8211;&lt;br /&gt;
Mugunth&lt;/p&gt;
&lt;p&gt;&lt;map name='google_ad_map_2020_8b86e81420c6776e'&gt;
&lt;area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/2020?pos=0' coords='1,2,367,28' /&gt;
&lt;area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/&gt;&lt;/map&gt;
&lt;img usemap='#google_ad_map_2020_8b86e81420c6776e' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;amp;client=&amp;amp;channel=&amp;amp;output=png&amp;amp;cuid=2020&amp;amp;url= http%3A%2F%2Fblog.mugunthkumar.com%2Ftech%2Fwindows-store-app-development-for-ios-developers%2F' /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href ="http://twitter.com/mugunthkumar"&gt;Follow me &lt;/a&gt; on Twitter&lt;/p&gt;
&lt;div class='yarpp-related-rss'&gt;
&lt;p&gt;Related posts:&lt;ol&gt;
&lt;li&gt;&lt;a href='http://blog.mugunthkumar.com/tech/ios-programming-training-courses-in-singapore/' rel='bookmark' title='iOS Programming training courses in Singapore'&gt;iOS Programming training courses in Singapore&lt;/a&gt; &lt;small&gt;After my book got pretty good reviews, I&amp;#8217;ve been approached...&lt;/small&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/p&gt;
&lt;img src='http://yarpp.org/pixels/8b86e81420c6776e456ee5dbf4b38381'/&gt;
&lt;/div&gt;
&lt;img src="http://feeds.feedburner.com/~r/MugunthKumar/~4/kE2qU1doX3I" height="1" width="1"/&gt;</content><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blog.mugunthkumar.com/tech/windows-store-app-development-for-ios-developers/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">0</slash:comments><feedburner:origLink>http://blog.mugunthkumar.com/tech/windows-store-app-development-for-ios-developers/</feedburner:origLink></entry><entry><title type="text">Performance improvements to MKNetworkKit</title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MugunthKumar/~3/oBKakwLP8Cg/" /><category term="Coding" /><category term="ios" /><category term="nsdateformatter" /><category term="performance" /><author><name>Mugunth Kumar</name></author><updated>2012-11-20T03:01:22-08:00</updated><id>http://blog.mugunthkumar.com/?p=2018</id><summary type="html">Over the past couple of weeks, I was profiling MKNetworkKit and looking for bottlenecks. I found around five major bottlenecks. Performance Fix 1: Decoding images in Background UIImage will not decompress the PNG/JPG image until it&amp;#8217;s actually displayed. This is fine for artwork or pattern images that you normally bundle with your iOS app. But [...]&lt;div class='yarpp-related-rss yarpp-related-none'&gt;

No related posts.
&lt;img src='http://yarpp.org/pixels/8b86e81420c6776e456ee5dbf4b38381'/&gt;
&lt;/div&gt;</summary><content type="html">&lt;p&gt;&lt;/p&gt;&lt;p&gt;Over the past couple of weeks, I was profiling &lt;a href="https://github.com/MugunthKumar/MKNetworkKit"&gt;MKNetworkKit&lt;/a&gt; and looking for bottlenecks.&lt;/p&gt;
&lt;p&gt;I found around five major bottlenecks.&lt;/p&gt;
&lt;span id="Performance_Fix_1:"&gt;&lt;h2&gt;Performance Fix 1:&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;&lt;strong&gt;Decoding images in Background&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;UIImage will not decompress the PNG/JPG image until it&amp;#8217;s actually displayed. This is fine for artwork or pattern images that you normally bundle with your iOS app. But for displaying avatar images on a Twitter timeline or a photo library application, the performance could be improved drastically by decompressing the image in the background. Thanks to &lt;a href="http://twitter.com/merowing_"&gt;Krzysztof Zabłocki (@merowing_)&lt;/a&gt; for the code snippet. &lt;/p&gt;
&lt;p&gt;You can now use the method, imageAtUrl:size:completionHandler:errorHandler: to get a decompressed image from a MKNetworkEngine.&lt;/p&gt;
&lt;span id="Performance_Fix_2:"&gt;&lt;h2&gt;Performance Fix 2:&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;&lt;strong&gt;Decoding JSONs in a background thread&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I added a method responseJSONWithCompletionHandler: to MKNetworkOperation to decode JSON in the background.&lt;br /&gt;
From here on, responseJSONWithCompletionHandler: is the recommended way to decode JSON instead of the older method, responseJSON.&lt;/p&gt;
&lt;span id="Performance_Fix_3:"&gt;&lt;h2&gt;Performance Fix 3:&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;&lt;strong&gt;Caching in a background thread&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Caching is now thread safe and runs in a serial GCD queue completely in background without blocking the UI. you wouldn&amp;#8217;t even know that the requests are being cached!&lt;/p&gt;
&lt;span id="Performance_Fix_4:"&gt;&lt;h2&gt;Performance Fix 4:&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;&lt;strong&gt;Replaced NSDateFormatter with strptime_l&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;MKNetworkOperation used NSDateFormatter to parse the dates in the Expires and Cache-Control header. While I did use a dispatch_once to mitigate the issue, dispatch_once did not eliminate the problem completely. The right way to do date formatting when the date format is fixed and unlocalized, is to &lt;a href="https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/DataFormatting/Articles/dfDateFormatting10_4.html"&gt;use strptime_l&lt;/a&gt; I was dabbling around with strptime_l today and got &lt;a href="https://github.com/Bo98/MKNetworkKit/commit/ef9630d246bf08128f96aeda13a62d52d647af62"&gt;this pull request from Bo98&lt;/a&gt;. He did an awesome job with strptime_l, and improved the overall performance.&lt;/p&gt;
&lt;span id="Performance_Fix_5:"&gt;&lt;h2&gt;Performance Fix 5:&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;There is one more performance tune up that could speed up the enqueueOperation. I&amp;#8217;m looking at it now. You should see another post in a couple of days.&lt;/p&gt;
&lt;p&gt;Overall, the latest on Github should offer a lot more performance. I hope you liked it. Keep the pull requests coming!&lt;/p&gt;
&lt;p&gt;Thanks!&lt;br /&gt;
&amp;#8211;&lt;br /&gt;
Mugunth&lt;/p&gt;
&lt;p&gt;&lt;map name='google_ad_map_2018_8b86e81420c6776e'&gt;
&lt;area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/2018?pos=0' coords='1,2,367,28' /&gt;
&lt;area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/&gt;&lt;/map&gt;
&lt;img usemap='#google_ad_map_2018_8b86e81420c6776e' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;amp;client=&amp;amp;channel=&amp;amp;output=png&amp;amp;cuid=2018&amp;amp;url= http%3A%2F%2Fblog.mugunthkumar.com%2Fcoding%2Fperformance-improvements-to-mknetworkkit%2F' /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href ="http://twitter.com/mugunthkumar"&gt;Follow me &lt;/a&gt; on Twitter&lt;/p&gt;
&lt;div class='yarpp-related-rss yarpp-related-none'&gt;
&lt;p&gt;No related posts.&lt;/p&gt;
&lt;img src='http://yarpp.org/pixels/8b86e81420c6776e456ee5dbf4b38381'/&gt;
&lt;/div&gt;
&lt;img src="http://feeds.feedburner.com/~r/MugunthKumar/~4/oBKakwLP8Cg" height="1" width="1"/&gt;</content><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blog.mugunthkumar.com/coding/performance-improvements-to-mknetworkkit/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">0</slash:comments><feedburner:origLink>http://blog.mugunthkumar.com/coding/performance-improvements-to-mknetworkkit/</feedburner:origLink></entry><entry><title type="text">Mobile apps and number of concurrent connections</title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MugunthKumar/~3/TpAt2fBU-TI/" /><category term="Articles" /><category term="best practices" /><category term="ios" /><category term="networking" /><author><name>Mugunth Kumar</name></author><updated>2012-11-08T03:15:46-08:00</updated><id>http://blog.mugunthkumar.com/?p=2000</id><summary type="html">HTTP RFC Spec 2616 Section 8.1.4 (http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html) says A single-user client SHOULD NOT maintain more than 2 connections with any server or proxy. A proxy SHOULD use up to 2*N connections to another server or proxy, where N is the number of simultaneously active users. While this spec was written quite a long time ago, [...]&lt;div class='yarpp-related-rss yarpp-related-none'&gt;

No related posts.
&lt;img src='http://yarpp.org/pixels/8b86e81420c6776e456ee5dbf4b38381'/&gt;
&lt;/div&gt;</summary><content type="html">&lt;p&gt;&lt;/p&gt;&lt;p&gt;HTTP RFC Spec 2616 Section 8.1.4 (&lt;a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html"&gt;http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html&lt;/a&gt;) says&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;A single-user client SHOULD NOT maintain more than 2 connections with any server or proxy. A proxy SHOULD use up to 2*N connections to another server or proxy, where N is the number of simultaneously active users.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;While this spec was written quite a long time ago, it&amp;#8217;s still a spec and you as a client developer should respect. Most browsers till IE8 did not allow more than two concurrent connections to the same server. IE 8 changed the trend. Steve Sounders has an excellent write up on this &lt;a href="http://www.stevesouders.com/blog/2008/03/20/roundup-on-parallel-connections/"&gt;here.&lt;/a&gt; Even with IE 8, Microsoft did limit the number of connections (to 6). The cap still exists and it&amp;#8217;s not &amp;#8220;unlimited&amp;#8221; and in 2012, most browsers don&amp;#8217;t allow more than 6 or 8 concurrent connections to the same server. (We are dealing with HTTP protocol and not torrents or others)&lt;/p&gt;
&lt;p&gt;In my opinion, an iOS client that acts a native client for your website should behave like a browser (minus the layout engine), adhering to every possible HTTP standard (Caching headers, Authorization headers, Keep-Alive and others). This is exactly what my iOS networking framework &lt;a href="https://github.com/MugunthKumar/MKNetworkKit"&gt;MKNetworkKit&lt;/a&gt;, tries to achieve.&lt;/p&gt;
&lt;span id="Effect_of_Multiple_Connections"&gt;&lt;h3&gt;Effect of Multiple Connections&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;Making multiple HTTP requests concurrently hurts the performance. To understand why, we should first understand briefly about how web servers are architected. Firstly, servers (whether it&amp;#8217;s a physical box in your office or a VPS or cloud instance) can handle only a given number of requests per second (depending on the hardware). In fact, most servers vie to handle 10,000 concurrent connections. (For the eager beaver, read about the &lt;a href="http://www.kegel.com/c10k.html"&gt;c10k problem&lt;/a&gt; that offers solutions on how to implement 10k requests concurrently on your server). When a server cannot handle the load, it&amp;#8217;s free to drop connections (again this is perfectly fine and an expected behaviour as per RFC). When a connection is dropped, a client retries the connection using a binary exponential back off algorithm (as per RFC 2616). So, achieving 10,000 concurrent connections per hardware is hard. So how do web server handle millions of users? With proper load balancing and making sure that a low Keep-Alive is sent to the client, a web server, tries to limit the number of concurrent connections.&lt;/p&gt;
&lt;span id="Keep-Alive"&gt;&lt;h3&gt;Keep-Alive&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;Most HTTP servers including Apache/nginx allows sysadmins to set a value called &amp;#8220;Keep-Alive&amp;#8221;. I believe you might have edited this value too. Keep-Alive dictates how long a connection will be kept open before the server forcefully closes it. A lower value means, the server can serve more users and a high value means less latency for already connected user. Apache 2&amp;#8242;s default value seems to be around 2 seconds. (This was originally 15 seconds before Apache 2). What that means is, if you make a request to your server (running apache) to get a list of items, and then when the user taps on the item to get the details, your second request would probably not use the same TCP connection (assuming your second request is started after 2 seconds). Initiating a new TCP connection is a slow process compared to fetching data over HTTP on an existing TCP connection. But unfortunately, servers are designed to cater to as many users as possible and not just your client and you just have to live with it.&lt;/p&gt;
&lt;p&gt;This limitation has a side effect. It increases the number of concurrent connections opened by a &lt;strong&gt;client&lt;/strong&gt; to a server. To workaround this, the RFC spec encourages clients not to maintain more than 2 connections per server. And let&amp;#8217;s all face it. &lt;a href="http://msdn.microsoft.com/en-us/library/cc304129(v=vs.85).aspx"&gt;IE breaks standards&lt;/a&gt;. (But Microsoft could have broken the standard because the standard was too old and was written before the era of XmlHttpRequest). IE 8 changed this limit to 6 and other browsers followed.&lt;/p&gt;
&lt;p&gt;When you open a higher number of concurrent connections (more than 6), say for a photo library app on an iPad that downloads 100 images for displaying it on the first screen, if your app is being used by 100 others at the same time (quite common, 100 users is not a huge number) you hit the 10,000 concurrent limit easily and your server will start closing connections. Without proper load balancing, your server will not even be able to handle a 100 concurrent users, a very poor engineering. (throwing more hardware at the problem is again poor engineering)&lt;/p&gt;
&lt;p&gt;So, what can you do as a iOS developer? Limit the number of parallel connections in your app to somewhere around 6 or 8. Now, won&amp;#8217;t throttling my download operations affect client side performance? No, apparently, limiting the number of operations will do more good than bad. Yes, it actually improves your performance. Let me explain.&lt;/p&gt;
&lt;span id="Example"&gt;&lt;h3&gt;Example&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;Let&amp;#8217;s assume that you are making a photo library iPad app (something similar to cool iris) that downloads 100 images to be displayed on the first screen. Let&amp;#8217;s assume that every image (thumbnail) you download is around 50 KB. Downloading 100 images is going to be around 5 MB. If your 3G bandwidth is around 1 Mbps (a fair assumption), it would probably take 40 seconds to download). If you have 100 parallel connections sharing the 1Mbps bandwidth, all 100 images will appear after 40 seconds. If you have 50 parallel connections, 50 images will appears after 20 seconds and the next 50 after 40 seconds. If you have 10 parallel connections, 10 images will appear progressively every 4 seconds, a much better user experience. So where do you exactly stop? RFC says, stop at 2 parallel connections. Most browsers however stop at 6 or 8 parallel connections. Mobile Safari, on my testing using &lt;a href="http://spasche.net/files/parallel_connections/"&gt;this website&lt;/a&gt; uses 2-6 based on the current network speed. While our own app cannot determine the speed of a network before hand (It&amp;#8217;s too painful to download a fat file and calculate the time it takes and get the speed and is not just worth it), it&amp;#8217;s better to use 6 connections on WiFi and 2 on mobile data network. Of course, this limit might change in future when LTE adoption becomes widespread, but restricting number of connections goes a long way in building a robust product (both client and the server) than opening up unlimited number of connections.&lt;/p&gt;
&lt;p&gt;It doesn&amp;#8217;t stop there. On the server side, if a client opens 100 connections at once, assuming a single machine can handle 10,000 concurrent connections, you limit the number of concurrent users to 100, which is bad. You have to throw more hardware for every 100 user. Not a great scalable service. By limiting the concurrent connections on client side to 5, you allow 2000 concurrent users (per machine/node) and this limit will actually do more good than bad as we saw in our previous example.&lt;/p&gt;
&lt;p&gt;Additionally, if you someone else, like ISP or a intermediate proxy server, limits the number of connections to say 6, your first 6 connections will go through. But 7th, 8th and nth operation will start and enter the &amp;#8220;isExecuting&amp;#8221; state within the NSOperationQueue. The NSURLConnection will start the connection and wait, but the connection:didReceiveResponse: will never be called on the delegate till one of the 6 operations, that you previously started completes. After 240 seconds, this operation will just timeout. You can avoid this scenario easily by preventing the 7th+ NSURLConnection to be started. While 240 seconds is a large number, you will easily hit this wait time with 6 concurrent connections trying to download a 50 kb thumbnail over a 10 Kbps edge/gprs network.&lt;/p&gt;
&lt;p&gt;Moreover, even in an ideal world where there are no proxies or ISPs to throttle (gasp!), if you don&amp;#8217;t limit the number of connections, the server can close them when load is high and again, you will get timeouts for some operations.&lt;/p&gt;
&lt;p&gt;A timeout in a image heavy app like this means, only few images will go through and your photo library app will display empty images/placeholders for the rest. Again, not a great user experience. User experience is not just slapping a beautiful UI onto your iOS app. The underlying engineering should be good as well.&lt;/p&gt;
&lt;span id="What_does_other_8220industry_leading8221_companies_recommend"&gt;&lt;h3&gt;What does other &amp;#8220;industry leading&amp;#8221; companies recommend?&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;Lastly, minimising concurrent HTTP requests on the client side is not something new. Both &lt;a href="http://developer.yahoo.com/performance/rules.html#num_http"&gt;Yahoo&lt;/a&gt; and &lt;a href="https://developers.google.com/speed/docs/best-practices"&gt;Google&amp;#8217;s&lt;/a&gt; best practices recommends that you to minimise concurrent HTTP requests. A web developer ensures that a browser doesn&amp;#8217;t make multiple HTTP requests by coalescing Javascript files and/or CSS file into one big file. An iOS developer does not have a choice apart from limiting the number of concurrent connections.&lt;/p&gt;
&lt;p&gt;Lastly, limiting the number of connections is not throttling. It&amp;#8217;s optimization. It&amp;#8217;s an optimization recommended by RFC and implemented by most browsers. You should implement them too. Throttling is limiting the bandwidth.&lt;/p&gt;
&lt;span id="MKNetworkKit"&gt;&lt;h3&gt;MKNetworkKit&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;MKNetworkKit has some nifty features to help you manage scenarios like this. MKNetworkKit uses a single shared queue and optimizes the number of concurrent connections based on the available network. As on date, it is 6 on WiFi and 2 on mobile networks. While browsers implement 6 concurrent connections per server, I do it per application. This is because, an iOS app mostly would normally won&amp;#8217;t have 6 concurrent connections talking to different servers. In most cases, your implementation will contain one API fetch and multiple CDN fetch. Limiting it per application will just average out.&lt;/p&gt;
&lt;p&gt;MKNetworkKit also coalesces multiple requests. Assume that you are a twitter client and you download the last 200 tweets in a user&amp;#8217;s timeline. While a stream might contain 200 tweets, there would be far less than 10 or 20 friends (statistically). As the user scrolls through the timeline, you shouldn&amp;#8217;t create operations to download 200 profile pictures. You should in fact a unique download operation per profile picture. Surprisingly, a twitter timeline containing the most recent 200 tweets will contain around 20 friends and 20 requests is all that you need to make. Fret not. With MKNetworkKit take care of this operation coalescing automatically. Even if you enqueue an image download operation twice, the actual URL fetch is performed exactly once.&lt;/p&gt;
&lt;p&gt;Any networking app can and should implement such performance related fine tuning measures and profile the performance. In fact, one of the hardest aspect of iOS programming is getting the performance right and in the upcoming edition of our book, &lt;a href="http://blog.mugunthkumar.com/products/ios-6-programming-pushing-the-limits/"&gt;iOS 6 Programming: Pushing the Limits&lt;/a&gt; we added a whole new chapter that explains memory and CPU optimisation using Instruments. You might want to check that out.&lt;/p&gt;
&lt;p&gt;Comments are welcome.&lt;/p&gt;
&lt;p&gt;&amp;#8211;&lt;br /&gt;
Mugunth&lt;/p&gt;
&lt;p&gt;&lt;map name='google_ad_map_2000_8b86e81420c6776e'&gt;
&lt;area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/2000?pos=0' coords='1,2,367,28' /&gt;
&lt;area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/&gt;&lt;/map&gt;
&lt;img usemap='#google_ad_map_2000_8b86e81420c6776e' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;amp;client=&amp;amp;channel=&amp;amp;output=png&amp;amp;cuid=2000&amp;amp;url= http%3A%2F%2Fblog.mugunthkumar.com%2Farticles%2Fmobile-apps-and-number-of-concurrent-connections%2F' /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href ="http://twitter.com/mugunthkumar"&gt;Follow me &lt;/a&gt; on Twitter&lt;/p&gt;
&lt;div class='yarpp-related-rss yarpp-related-none'&gt;
&lt;p&gt;No related posts.&lt;/p&gt;
&lt;img src='http://yarpp.org/pixels/8b86e81420c6776e456ee5dbf4b38381'/&gt;
&lt;/div&gt;
&lt;img src="http://feeds.feedburner.com/~r/MugunthKumar/~4/TpAt2fBU-TI" height="1" width="1"/&gt;</content><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blog.mugunthkumar.com/articles/mobile-apps-and-number-of-concurrent-connections/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">2</slash:comments><feedburner:origLink>http://blog.mugunthkumar.com/articles/mobile-apps-and-number-of-concurrent-connections/</feedburner:origLink></entry><entry><title type="text">iPhone 5 Wallpaper – New York City</title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MugunthKumar/~3/RKFRuIXYJcc/" /><category term="Wallpapers" /><category term="new york city" /><category term="wallpapers" /><author><name>Mugunth Kumar</name></author><updated>2012-09-27T05:00:17-07:00</updated><id>http://blog.mugunthkumar.com/?p=1966</id><summary type="html">I&amp;#8217;m a fan of city skylines. Here is my own shot of New York City from Empire State Building for your shiny new iPhone 5. It looks like this on my iPhone. Resized just the right way so that the city skyline stands out and the sky goes behind the date/time. Ok, this photo doesn&amp;#8217;t do [...]&lt;div class='yarpp-related-rss yarpp-related-none'&gt;

No related posts.
&lt;img src='http://yarpp.org/pixels/8b86e81420c6776e456ee5dbf4b38381'/&gt;
&lt;/div&gt;</summary><content type="html">&lt;p&gt;&lt;/p&gt;&lt;p&gt;I&amp;#8217;m a fan of city skylines. Here is my own shot of New York City from Empire State Building for your shiny new iPhone 5.&lt;/p&gt;
&lt;div class="wp-caption aligncenter" style="width: 330px"&gt;&lt;a href="http://blog.mugunthkumar.com/wp-content/uploads/NYC.jpg"&gt;&lt;img style="display: block; border: 0px;" title="New York City" src="http://blog.mugunthkumar.com/wp-content/uploads/NYC.jpg" alt="New York City" width="320" height="568" border="0" /&gt;&lt;/a&gt;&lt;p class="wp-caption-text"&gt;New York City &amp;#8211; Tap this link to view the actual size&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;It looks like this on my iPhone. Resized just the right way so that the city skyline stands out and the sky goes behind the date/time.&lt;/p&gt;
&lt;p style="text-align: center;"&gt;&lt;img class="aligncenter" style="display: block; border: 0px;" title="DSC01005.JPG" src="http://blog.mugunthkumar.com/wp-content/uploads/DSC01005.jpg" alt="DSC01005" width="504" height="504" border="0" /&gt;&lt;/p&gt;
&lt;p&gt;Ok, this photo doesn&amp;#8217;t do justice. &lt;a href="http://blog.mugunthkumar.com/wp-content/uploads/NYC.jpg" target="_blank"&gt;Download it from here&lt;/a&gt; and try it yourself.&lt;/p&gt;
&lt;p&gt;&amp;#8211;&lt;br /&gt;
Mugunth&lt;/p&gt;
&lt;p&gt;&lt;map name='google_ad_map_1966_8b86e81420c6776e'&gt;
&lt;area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1966?pos=0' coords='1,2,367,28' /&gt;
&lt;area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/&gt;&lt;/map&gt;
&lt;img usemap='#google_ad_map_1966_8b86e81420c6776e' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;amp;client=&amp;amp;channel=&amp;amp;output=png&amp;amp;cuid=1966&amp;amp;url= http%3A%2F%2Fblog.mugunthkumar.com%2Fwallpaper%2Fiphone-5-wallpaper-new-york-city%2F' /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href ="http://twitter.com/mugunthkumar"&gt;Follow me &lt;/a&gt; on Twitter&lt;/p&gt;
&lt;div class='yarpp-related-rss yarpp-related-none'&gt;
&lt;p&gt;No related posts.&lt;/p&gt;
&lt;img src='http://yarpp.org/pixels/8b86e81420c6776e456ee5dbf4b38381'/&gt;
&lt;/div&gt;
&lt;img src="http://feeds.feedburner.com/~r/MugunthKumar/~4/RKFRuIXYJcc" height="1" width="1"/&gt;</content><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blog.mugunthkumar.com/wallpaper/iphone-5-wallpaper-new-york-city/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">3</slash:comments><feedburner:origLink>http://blog.mugunthkumar.com/wallpaper/iphone-5-wallpaper-new-york-city/</feedburner:origLink></entry><entry><title type="text">iOS Tip: Applying a background pattern globally to all your views</title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MugunthKumar/~3/beJSgRP9glw/" /><category term="Coding" /><category term="design pattern" /><category term="iphone 5" /><author><name>Mugunth Kumar</name></author><updated>2012-09-27T04:00:40-07:00</updated><id>http://blog.mugunthkumar.com/?p=1951</id><summary type="html">Applying a pattern is something that you already know. But supporting the older 3.5 inch iPhones and the iPhone 5&amp;#8242;s taller resolution means, shipping two sets of background images and choosing the right one depending on the device. However, there are at least two drawbacks of the above mentioned method. Firstly, shipping multiple images means [...]&lt;div class='yarpp-related-rss'&gt;

Related posts:&lt;ol&gt;
&lt;li&gt;&lt;a href='http://blog.mugunthkumar.com/coding/supporting-the-iphone-5/' rel='bookmark' title='Supporting the iPhone 5'&gt;Supporting the iPhone 5&lt;/a&gt; &lt;small&gt;Update: A Russian translation available at osxdev.ru here iPhone 5...&lt;/small&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;img src='http://yarpp.org/pixels/8b86e81420c6776e456ee5dbf4b38381'/&gt;
&lt;/div&gt;</summary><content type="html">&lt;p&gt;&lt;/p&gt;&lt;p&gt;Applying a pattern is something that you already know. But supporting the older 3.5 inch iPhones and the iPhone 5&amp;#8242;s taller resolution means, shipping two sets of background images and choosing the right one depending on the device.&lt;br /&gt;
However, there are at least two drawbacks of the above mentioned method. Firstly, shipping multiple images means you are increasing the download size of your app. Default.png and Background.png are usually the biggest files in most applications and adding another background for iPhone 5 is a felony. Secondly, code switch based on device is something I would not recommend writing explicitly, especially, if there is a way around, use it.&lt;/p&gt;
&lt;p&gt;I instead recommend &lt;code&gt;colorWithPatternImage:&lt;/code&gt; and I&amp;#8217;m going to show you how I do this.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step 1: &lt;/strong&gt;Subclass UIViewController and create your own. I recommend this to avoid code duplication. In the viewDidLoad method, create a pattern layer and add it as a sublayer of your view. You should strongly own the pattern layer.&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #002200;"&gt;-&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;void&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;viewDidLoad
&lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;super viewDidLoad&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
&amp;nbsp;
self.patternLayer &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;CALayer layer&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
self.patternLayer.frame &lt;span style="color: #002200;"&gt;=&lt;/span&gt; self.view.bounds;
self.patternLayer.backgroundColor &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;UIColor colorWithPatternImage&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;UIImage imageNamed&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;BackgroundPattern&amp;quot;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;.CGColor;
self.patternLayer.opacity &lt;span style="color: #002200;"&gt;=&lt;/span&gt; 1.0f;
&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;self.view.layer insertSublayer&lt;span style="color: #002200;"&gt;:&lt;/span&gt;self.patternLayer atIndex&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #2400d9;"&gt;0&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
&lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Step 2: &lt;/strong&gt;In your viewWillLayoutSubviews method, adjust the pattern layer&amp;#8217;s frame. This is for iPhone 5 compatibility.&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #002200;"&gt;-&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;void&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;viewWillLayoutSubviews &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
self.patternLayer.frame &lt;span style="color: #002200;"&gt;=&lt;/span&gt; self.view.bounds;
&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;super viewWillLayoutSubviews&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
&lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;That&amp;#8217;s all. Any view that is inheriting from this subclass of UIViewController will automatically get the background pattern. You can go on and apply corner radius, drop shadows and play around here to apply themes globally.&lt;/p&gt;
&lt;p&gt;&amp;#8211;&lt;br /&gt;
Mugunth&lt;/p&gt;
&lt;p&gt;&lt;map name='google_ad_map_1951_8b86e81420c6776e'&gt;
&lt;area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1951?pos=0' coords='1,2,367,28' /&gt;
&lt;area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/&gt;&lt;/map&gt;
&lt;img usemap='#google_ad_map_1951_8b86e81420c6776e' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;amp;client=&amp;amp;channel=&amp;amp;output=png&amp;amp;cuid=1951&amp;amp;url= http%3A%2F%2Fblog.mugunthkumar.com%2Fcoding%2Fios-tip-applying-a-background-pattern-globally-to-all-your-views%2F' /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href ="http://twitter.com/mugunthkumar"&gt;Follow me &lt;/a&gt; on Twitter&lt;/p&gt;
&lt;div class='yarpp-related-rss'&gt;
&lt;p&gt;Related posts:&lt;ol&gt;
&lt;li&gt;&lt;a href='http://blog.mugunthkumar.com/coding/supporting-the-iphone-5/' rel='bookmark' title='Supporting the iPhone 5'&gt;Supporting the iPhone 5&lt;/a&gt; &lt;small&gt;Update: A Russian translation available at osxdev.ru here iPhone 5...&lt;/small&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/p&gt;
&lt;img src='http://yarpp.org/pixels/8b86e81420c6776e456ee5dbf4b38381'/&gt;
&lt;/div&gt;
&lt;img src="http://feeds.feedburner.com/~r/MugunthKumar/~4/beJSgRP9glw" height="1" width="1"/&gt;</content><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blog.mugunthkumar.com/coding/ios-tip-applying-a-background-pattern-globally-to-all-your-views/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">5</slash:comments><feedburner:origLink>http://blog.mugunthkumar.com/coding/ios-tip-applying-a-background-pattern-globally-to-all-your-views/</feedburner:origLink></entry></feed>
