{"id":295,"date":"2011-05-23T17:12:44","date_gmt":"2011-05-24T00:12:44","guid":{"rendered":"http:\/\/mattfife.net\/wordpress\/?p=295"},"modified":"2012-08-12T19:17:00","modified_gmt":"2012-08-13T02:17:00","slug":"iphone-programming-learnings","status":"publish","type":"post","link":"https:\/\/mattfife.com\/?p=295","title":{"rendered":"iPhone programming &#8211; Learnings"},"content":{"rendered":"<p>From the wayback machine&#8230;<\/p>\n<p>I found a half-completed post on when I was first learning to program on the iPhone.\u00a0 I think these things are all still valid&#8230;<br \/>\nSo, I&#8217;ve embarked on an ambitious programming project.\u00a0 One that is now 1\/3 of the way complete (first third was the &#8216;heaviest lifting&#8217; part of the project &#8211; took about a month of outsourced grunt work).\u00a0 The next 1\/3 involves programming an app on the iPhone\/iTouch.\u00a0 I thought that would be the easy part, but as it turns out &#8211; there is a substantial learning curve that one should be aware of before starting this endeavor.\u00a0 Here are some of the learnings I&#8217;ve found so far after having just got the bare bones of my own app up and running.<\/p>\n<ol>\n<li><strong>Apple&#8217;s documentation is very robust &#8211; but frustratingly &#8216;useless&#8217; at times.<\/strong>\u00a0 They provide many very detailed and excellent vertical stacks of information.\u00a0 Want to learn about pooled allocators?\u00a0 They have a document that gives you all the information you could ever want.\u00a0 But not in the context of how you&#8217;d actually use them &#8211; or why you hit various problems you hit. \u00a0 You&#8217;ll find yourself sifting around from document to document trying to find out why your NSString object is throwing an exception when returning from a function &#8211; only to find the real reason is buried in the memory management section of the Cocoa programming guide &#8211; not anywhere near the NSString documentation or their samples<strong>.\u00a0<\/strong><\/li>\n<li><strong>You need to learn Objective C and Cocoa<\/strong>. &#8211; and learn them in THAT order.\u00a0 It&#8217;s annoying, but try to find a good Objective C book first.\u00a0 There aren&#8217;t many of them.\u00a0 There are lots of bad ones though.\u00a0 Learn how to write a class, add functions with multiple calling parameters, how to make calls to classes, and how allocation works.\u00a0 That last one is key.\u00a0 Really spend time learning why:<br \/>\n[[NSString alloc] init]<br \/>\nis the right way to allocate and initialize an object and then learn why:<br \/>\nNSString *s = [[NSString alloc] initFromString:@&#8221;hello&#8221;];<br \/>\n[s appendString:@&#8221;this string now leaks&#8221;];<br \/>\nleaks memory.\u00a0 And how the autoAllocator pools work\/don&#8217;t work.\u00a0 This is all huge and the first biggest gotcha&#8217;s your get hit with right off the bat.<\/li>\n<li><strong>You&#8217;ll struggle to get even a 5 line program working at first<\/strong>.\u00a0 Your first Objective C\/Cocoa programs will be very painful.\u00a0 The simplest things will feel like fighting a brick wall.\u00a0 I tried to do a simple enum, and kept getting burned by an invalid class definition.\u00a0 Wha?\u00a0 The objective C compiler on the iPhone requires you typedef your enums and structs:<br \/>\nenum newEnum { a, b, c, d };  (NOPE &#8211; will cause a compiler error in whatever line follows this definition)<br \/>\ntypedef enum { a, b, c, d } newEnum;  (yes &#8211; works)<br \/>\nJust millions of little things like that.\u00a0 Again, logical if you put your old C\/gcc hat on, but it&#8217;s been a bit since I last had that hat on and it had some dust on it&#8230;<\/li>\n<li><strong>The GUI IDE is great &#8211; if you do things they way THEY want them and only for straight-forward designs.\u00a0 <\/strong>The interfaces for GUI controls holds very much like Win32\/X programming philosophies, albeit the syntax is very different.\u00a0 X Code comes with it&#8217;s own WYSIWYG GUI editor, but I found it very limited if you&#8217;re going to come up with any kind of innovative interface.\u00a0 If you just want some standard buttons\/etc &#8211; you&#8217;re probably fine.\u00a0 But if you want to have some interesting scrolling effects\/etc &#8211; you best be ready to spend another few days learning how the UI control systems work underneath and experimenting.\u00a0 The built-in GUI editor reminds me of the old VS2005 GUI editor that you could drag-n-drop controls, compile, and you&#8217;d see the results.\u00a0 If you want any dynamic elements &#8211; I haven&#8217;t found a way to do that using their gui editor.\u00a0 And if you want to embed controls on scrolling panels and some other more modern effects &#8211; you&#8217;ll be tossing the GUI editor altogether.\u00a0 Trouble is, you spend a good bit of time learning how the built-in GUI system works, find out it won&#8217;t do the thing you need without tons of digging through forums and &#8216;tricking&#8217; the thing to do what you want, then give up and have to learn a bunch of NEW stuff when you give up and decide to just dynamically\/hand-generate the controls yourself.\u00a0 Frustrating.<\/li>\n<\/ol>\n<pre class=\"code\"><\/pre>\n<pre class=\"code\"><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>From the wayback machine&#8230; I found a half-completed post on when I was first learning to program on the iPhone.\u00a0 I think these things are all still valid&#8230; So, I&#8217;ve embarked on an ambitious programming project.\u00a0 One that is now 1\/3 of the way complete (first third was the &#8216;heaviest lifting&#8217; part of the project &#8211; took about a month of outsourced grunt work).\u00a0 The next 1\/3 involves programming an app on the iPhone\/iTouch.\u00a0 I thought that would be the&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/mattfife.com\/?p=295\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[7],"tags":[],"class_list":["post-295","post","type-post","status-publish","format-standard","hentry","category-technicalprogramming"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4WECr-4L","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/mattfife.com\/index.php?rest_route=\/wp\/v2\/posts\/295","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mattfife.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mattfife.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mattfife.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mattfife.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=295"}],"version-history":[{"count":1,"href":"https:\/\/mattfife.com\/index.php?rest_route=\/wp\/v2\/posts\/295\/revisions"}],"predecessor-version":[{"id":571,"href":"https:\/\/mattfife.com\/index.php?rest_route=\/wp\/v2\/posts\/295\/revisions\/571"}],"wp:attachment":[{"href":"https:\/\/mattfife.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=295"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mattfife.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=295"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mattfife.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=295"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}