iPhone Development Overview

5,986 views
5,809 views

Published on

Summary of what you need to know to get started with iPhone development: your relationship with Apple, developer tools, the iPhone Platform, and Objective-C

Published in: Technology, Business
0 Comments
20 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
5,986
On SlideShare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
659
Comments
0
Likes
20
Embeds 0
No embeds

No notes for slide

iPhone Development Overview

  1. 1. iPhone Application Development William Taysom 2009 April 22
  2. 2. The iPhone.
  3. 3. January 9, 2007 Introduced in 2007.
  4. 4. 30 Million Sold 30 Million Sold.
  5. 5. An impessive device.
  6. 6. • 480×320 display • 163ppi (50% more than your MacBook) • 8GB, 16GB, even 32GB of Storage Large display, high resolution, gigabyes of storage, ...
  7. 7. • Speaker • Mic • Headphone ...a speaker, mic, headphone, ...
  8. 8. • Camera • Wireless • GPS ...camera, wireless, GPS, ...
  9. 9. • Accelerometer • Ambient Light Sensor • Proximity Sensor ...accelerometer, light sensor, proximity sensor, ...
  10. 10. • And it’s a Phone. ...and itʼs a phone. But thatʼs not why weʼre here.
  11. 11. This is why weʼre here. 25,000 Apps.
  12. 12. 1 billion downloads.
  13. 13. You want some. You want some.
  14. 14. I will show you how. I will show you how.
  15. 15. iPhone application development has four aspects: • Your relationship with Apple, • the iPhone developer tools, • the iPhone Platform, and • the Objective-C programming language.
  16. 16. iPhone application development has four aspects: • Your relationship with Apple, • the iPhone developer tools, • the iPhone Platform, and • the Objective-C programming language.
  17. 17. iPhone application development has four aspects: • Your relationship with Apple, • the iPhone developer tools, • the iPhone Platform, and • the Objective-C programming language.
  18. 18. iPhone application development has four aspects: • Your relationship with Apple, • the iPhone developer tools, • the iPhone Platform, and • the Objective-C programming language.
  19. 19. iPhone application development has four aspects: • Your relationship with Apple, • the iPhone developer tools, • the iPhone Platform, and • the Objective-C programming language.
  20. 20. Letʼs talk about your relationship with Apple.
  21. 21. • Apple makes the device. • Apple provides the tools. • Apple approves your apps. Apple makes the device. Apple provides the tools. Apple approves your apps.
  22. 22. • You will have a relationship with Apple. You will have a relationship with Apple. Your relationship is mediated by three web sites:
  23. 23. iPhone Dev Center ...the iPhone Dev Center, ...
  24. 24. iPhone Developer Program Portal ...the iPhone Developer Program Portal, ...
  25. 25. iTunes Connect ...and iTunes Connect.
  26. 26. This chart summarizes the iPhone development process from signing up with the Dev Center • to seeing your app on the AppStore.
  27. 27. This chart summarizes the iPhone development process from signing up with the Dev Center • to seeing your app on the AppStore.
  28. 28. Your journey begins...
  29. 29. Your journey begins...
  30. 30. ...at the iPhone Dev Center.
  31. 31. iPhone Dev Center Letʼs check it out.
  32. 32. This is where you download the SDK, ...
  33. 33. This is where you download the SDK, ...
  34. 34. ...and is one place where you can read documention.
  35. 35. With the SDK, you are ready to develop your app. In the mean time, ...
  36. 36. ...you should sign up for the iPhone Developer Program.
  37. 37. From the iPhone Dev Cenver, • you learn more about the Developer Program.
  38. 38. From the iPhone Dev Cenver, • you learn more about the Developer Program.
  39. 39. “iPhone Developer Program: The fastest path from code to customer.” The Program isnʼt just the fastest path: itʼs the only path. To put your App on a device or on the store, you need to join the program.
  40. 40. After signing up, you need to be approved. With the Standard program, you sign up as an individual or as a corporation. We signed up as a corporation. We needed to fax Apple a copy of our Articles of Incorporation. Then they called us for confirmation. Then we needed to call them again after they sent us the wrong form email. • In total, the process took us about a month.
  41. 41. After signing up, you need to be approved. With the Standard program, you sign up as an individual or as a corporation. We signed up as a corporation. We needed to fax Apple a copy of our Articles of Incorporation. Then they called us for confirmation. Then we needed to call them again after they sent us the wrong form email. • In total, the process took us about a month.
  42. 42. Once approved, • you visit the Program Portal.
  43. 43. Once approved, • you visit the Program Portal.
  44. 44. iPhone Developer Program Portal The portal provides you with provisioning profiles.
  45. 45. A provisioning profile allows you to sign apps. A signature gives you permission to test an app on a device or to prepare an app for distribution.
  46. 46. iPhone Development Certificate App ID Unique Device ID You need to collect three things in order to generate a provisioning profile:
  47. 47. iPhone Development who Certificate App ID Unique Device ID An iPhone Development Certificate tells who will use the profile.
  48. 48. iPhone Development who Certificate App ID what Unique Device ID An app ID identifies what app the person is working on.
  49. 49. iPhone Development who Certificate App ID what Unique Device ID where A unique device ID determines where the app will be used, which device or the store.
  50. 50. It's a bit like the game Cleudo: who done it, where, and with what weapon.
  51. 51. While youʼre preparing your app, ...
  52. 52. While youʼre preparing your app, ...
  53. 53. ...you should visit iTunes Connect. iTunes Connect is...
  54. 54. iTunes Connect ...your backdoor enterance into the iTunes Store.
  55. 55. From iTunes Connect, • you fill out a paid applications contact so that you can sell your app on the store. You need to provide Apple with your bank and tax info. They need to verify it. The turnaround can be a few days or weeks.
  56. 56. From iTunes Connect, • you fill out a paid applications contact so that you can sell your app on the store. You need to provide Apple with your bank and tax info. They need to verify it. The turnaround can be a few days or weeks.
  57. 57. While youʼre waiting for your contract, you can upload your app and its accompanying artwork.
  58. 58. At this point, you are waiting for your contract and for app approval. Though people have been stuck waiting, my first app was approved within 24 hours. Since then, Iʼve always received feedback within a few days.
  59. 59. Okay, • back to the top.
  60. 60. Okay, • back to the top.
  61. 61. Start by signing up with iPhone Dev Center. Download the SDK. Work on your app.
  62. 62. Start by signing up with iPhone Dev Center. Download the SDK. Work on your app.
  63. 63. Sign up for the iPhone Developer program.
  64. 64. Sign up for the iPhone Developer program.
  65. 65. Go through the approval process.
  66. 66. Go through the approval process.
  67. 67. Gather info for the program portal. • Fill out the paid applications contract from iTunes Connect. Submit your app. • Wait for approval.
  68. 68. Gather info for the program portal. • Fill out the paid applications contract from iTunes Connect. Submit your app. • Wait for approval.
  69. 69. Gather info for the program portal. • Fill out the paid applications contract from iTunes Connect. Submit your app. • Wait for approval.
  70. 70. Gather info for the program portal. • Fill out the paid applications contract from iTunes Connect. Submit your app. • Wait for approval.
  71. 71. Enjoy the fruits of your labor.
  72. 72. That is your relationship with Apple.
  73. 73. Letʼs talk about tools. The iPhone SDK includes everything you need for iPhone (and Mac) development.
  74. 74. We will use four tools: • Xcode • The iPhone Simulator • Interface Builder • Instruments
  75. 75. We will use four tools: • Xcode • The iPhone Simulator • Interface Builder • Instruments
  76. 76. We will use four tools: • Xcode • The iPhone Simulator • Interface Builder • Instruments
  77. 77. We will use four tools: • Xcode • The iPhone Simulator • Interface Builder • Instruments
  78. 78. We will use four tools: • Xcode • The iPhone Simulator • Interface Builder • Instruments
  79. 79. Xcode is Apple's integrated development environment. We will spend most of our time in it.
  80. 80. Xcode is a front end for command-line utilities: • compiling with gcc, • linking with ld, • debugging with gdb, and • version control (also called source code management): svn, cvs, or Perforce.
  81. 81. • compling ↣ gcc Xcode is a front end for command-line utilities: • compiling with gcc, • linking with ld, • debugging with gdb, and • version control (also called source code management): svn, cvs, or Perforce.
  82. 82. • compling ↣ gcc • linking ↣ ld Xcode is a front end for command-line utilities: • compiling with gcc, • linking with ld, • debugging with gdb, and • version control (also called source code management): svn, cvs, or Perforce.
  83. 83. • compling ↣ gcc • linking ↣ ld • debugging ↣ gdb Xcode is a front end for command-line utilities: • compiling with gcc, • linking with ld, • debugging with gdb, and • version control (also called source code management): svn, cvs, or Perforce.
  84. 84. • compling ↣ gcc • linking ↣ ld • debugging ↣ gdb • SCM ↣ svn, cvs, Perforce Xcode is a front end for command-line utilities: • compiling with gcc, • linking with ld, • debugging with gdb, and • version control (also called source code management): svn, cvs, or Perforce.
  85. 85. Window Types Xcode has many types of windows:
  86. 86. Editor ...the editor, ...
  87. 87. Documentation ...documentation, .. .
  88. 88. Build ...build, .. .
  89. 89. Console ...debugging console, ...
  90. 90. Debugger ...debugger, .. .
  91. 91. Project ...the project window (Xcodeʼs main window), ...
  92. 92. Info ...info windows, ...
  93. 93. Organizer ...an organizer for your iPhone, ...
  94. 94. SCM ...and source code managment.
  95. 95. We will see all of these windows before weʼre done with Xcode.
  96. 96. The iPhone Simulator is great for everyday testing and debugging.
  97. 97. Looks just like the real thing in portrait...
  98. 98. ...and in landscape.
  99. 99. Thatʼs the gist of the simulator.
  100. 100. Interface Builder helps you layout the views for your app.
  101. 101. These are your primary IB windows.
  102. 102. Main Window The main window shows all of the objects in your interface builder document.
  103. 103. View Window The view window is where you layout the subviews of a view.
  104. 104. Attribute Inspector The inspector allows you to edit properties of your objects. Here we see the visual attributes of a slider.
  105. 105. Connections Inspector And here we see connections between the slider and other objects.
  106. 106. Interface Builder can remove the guesswork of in-code layout. But be warned. IB can trip you up due to limitations and bugs.
  107. 107. Instruments is used for profiling and, ...
  108. 108. ...most importantly, itʼs used in checking for memory leaks.
  109. 109. We will have some good runs with Instruments over the next few days.
  110. 110. These are tools which weʼll be using. However, the SDK offers many more.
  111. 111. We have graphics tools, ...
  112. 112. ...performance tools, ...
  113. 113. ...utilities, .. .
  114. 114. ...and Dashcode. Before native iPhone apps were an option, Dashcode was created to make iPhone specific Web Applications.
  115. 115. Hereʼs Dashcode. If it turns out that native development wonʼt work well for you or if you have stronger experience with web development, ...
  116. 116. ...I recommend that you look into Dashcode.
  117. 117. Xcode, iPhone Simulator, Interface Builder, Instruments...
  118. 118. ...these are the tools that weʼll be using.
  119. 119. Turn your attention to the iPhone platform.
  120. 120. The iPhone OS provides several layers of services. Services on higher layers abstract away details from services on lower layers. Services on lower layers provide more flexibility as well as more inconvenience and tedium. Letʼs start at the bottom.
  121. 121. Just like Mac OS X, the iPhone is built on the Mach UNIX kernel. Core OS exposes common UNIX libraries.
  122. 122. Core OS POSIX threads for in shared state multithreaded concurrency. • BSD sockets for low level TCP and UDP networking. • Standard C libraries including stdio, stdlib, and the rest.
  123. 123. Core OS • POSIX Threads ↣ Concurrency POSIX threads for in shared state multithreaded concurrency. • BSD sockets for low level TCP and UDP networking. • Standard C libraries including stdio, stdlib, and the rest.
  124. 124. Core OS • POSIX Threads ↣ Concurrency • BSD Sockets ↣ TCP & UDP Networking POSIX threads for in shared state multithreaded concurrency. • BSD sockets for low level TCP and UDP networking. • Standard C libraries including stdio, stdlib, and the rest.
  125. 125. Core OS • POSIX Threads ↣ Concurrency • BSD Sockets ↣ TCP & UDP Networking • <stdio.h> <stdlib.h> ...the rest POSIX threads for in shared state multithreaded concurrency. • BSD sockets for low level TCP and UDP networking. • Standard C libraries including stdio, stdlib, and the rest.
  126. 126. Core services include OS X specific libraries as well as popular, relatively new C libraries.
  127. 127. Core services include OS X specific libraries as well as popular, relatively new C libraries.
  128. 128. Core Services Core foundation is the plain C library which mirrors Objective-C Foundation classes. • Core Location enables your iPhone to determine where it is. • SQLite is for lightweight SQL databases. • libxml2 is for heavy duty XML processing.
  129. 129. Core Services • Core Foundation ↣ Foundation Mirror Core foundation is the plain C library which mirrors Objective-C Foundation classes. • Core Location enables your iPhone to determine where it is. • SQLite is for lightweight SQL databases. • libxml2 is for heavy duty XML processing.
  130. 130. Core Services • Core Foundation ↣ Foundation Mirror • Core Location ↣ GPS Core foundation is the plain C library which mirrors Objective-C Foundation classes. • Core Location enables your iPhone to determine where it is. • SQLite is for lightweight SQL databases. • libxml2 is for heavy duty XML processing.
  131. 131. Core Services • Core Foundation ↣ Foundation Mirror • Core Location ↣ GPS • SQLite ↣ SQL Database Core foundation is the plain C library which mirrors Objective-C Foundation classes. • Core Location enables your iPhone to determine where it is. • SQLite is for lightweight SQL databases. • libxml2 is for heavy duty XML processing.
  132. 132. Core Services • Core Foundation ↣ Foundation Mirror • Core Location ↣ GPS • SQLite ↣ SQL Database • libxml2 ↣ XML Processing Core foundation is the plain C library which mirrors Objective-C Foundation classes. • Core Location enables your iPhone to determine where it is. • SQLite is for lightweight SQL databases. • libxml2 is for heavy duty XML processing.
  133. 133. The media layer supports 2D and 3D graphics, audio, and video.
  134. 134. The media layer supports 2D and 3D graphics, audio, and video.
  135. 135. Media For audio, we have Core Audio and OpenAL. • OpenGL ES is geared toward 3D graphics. • Quartz, also called Core Graphics, provides 2D graphics support. • Core Animation provides all those animated effects we see on the iPhone and the Mac • including this presentation. •
  136. 136. Media • Core Audio & OpenAL ↣ Audio For audio, we have Core Audio and OpenAL. • OpenGL ES is geared toward 3D graphics. • Quartz, also called Core Graphics, provides 2D graphics support. • Core Animation provides all those animated effects we see on the iPhone and the Mac • including this presentation. •
  137. 137. Media • Core Audio & OpenAL ↣ Audio • OpenGL ES ↣ 3D Graphics For audio, we have Core Audio and OpenAL. • OpenGL ES is geared toward 3D graphics. • Quartz, also called Core Graphics, provides 2D graphics support. • Core Animation provides all those animated effects we see on the iPhone and the Mac • including this presentation. •
  138. 138. Media • Core Audio & OpenAL ↣ Audio • OpenGL ES ↣ 3D Graphics • Quartz (Core Graphics) ↣ 2D Graphics For audio, we have Core Audio and OpenAL. • OpenGL ES is geared toward 3D graphics. • Quartz, also called Core Graphics, provides 2D graphics support. • Core Animation provides all those animated effects we see on the iPhone and the Mac • including this presentation. •
  139. 139. Media • Core Audio & OpenAL ↣ Audio • OpenGL ES ↣ 3D Graphics • Quartz (Core Graphics) ↣ 2D Graphics • Core Animation ↣ Animated Effects For audio, we have Core Audio and OpenAL. • OpenGL ES is geared toward 3D graphics. • Quartz, also called Core Graphics, provides 2D graphics support. • Core Animation provides all those animated effects we see on the iPhone and the Mac • including this presentation. •
  140. 140. For audio, we have Core Audio and OpenAL. • OpenGL ES is geared toward 3D graphics. • Quartz, also called Core Graphics, provides 2D graphics support. • Core Animation provides all those animated effects we see on the iPhone and the Mac • including this presentation. •
  141. 141. Cocoa Touch contains the Objective-C frameworks you use to build your application.
  142. 142. Cocoa Touch contains the Objective-C frameworks you use to build your application.
  143. 143. Foundation Foundation is the essential Objective-C framework. Foundation contains: • NSObject, the root of the Objective-C class hierarchy, • Data type wrappers, • Collections, • Local filesystem access, • HTTP requests, and much more.
  144. 144. Foundation • NSObject Foundation is the essential Objective-C framework. Foundation contains: • NSObject, the root of the Objective-C class hierarchy, • Data type wrappers, • Collections, • Local filesystem access, • HTTP requests, and much more.
  145. 145. Foundation • NSObject • NSString, NSNumber, NSNull Foundation is the essential Objective-C framework. Foundation contains: • NSObject, the root of the Objective-C class hierarchy, • Data type wrappers, • Collections, • Local filesystem access, • HTTP requests, and much more.
  146. 146. Foundation • NSObject • NSString, NSNumber, NSNull • NSArray, NSDictionary, NSSet Foundation is the essential Objective-C framework. Foundation contains: • NSObject, the root of the Objective-C class hierarchy, • Data type wrappers, • Collections, • Local filesystem access, • HTTP requests, and much more.
  147. 147. Foundation • NSObject • NSString, NSNumber, NSNull • NSArray, NSDictionary, NSSet • NSFileManager, NSFileHandle Foundation is the essential Objective-C framework. Foundation contains: • NSObject, the root of the Objective-C class hierarchy, • Data type wrappers, • Collections, • Local filesystem access, • HTTP requests, and much more.
  148. 148. Foundation • NSObject • NSString, NSNumber, NSNull • NSArray, NSDictionary, NSSet • NSFileManager, NSFileHandle • NSURL, NSURLRequest, NSURLResponse Foundation is the essential Objective-C framework. Foundation contains: • NSObject, the root of the Objective-C class hierarchy, • Data type wrappers, • Collections, • Local filesystem access, • HTTP requests, and much more.
  149. 149. CocoaAsyncSocket For TCP and UDP networking, nothing beats CocoaAsyncSocket. Though not part of the iPhone SDK, CocoaAsyncSocket is such an valuable networking library that I can't help but mention it.
  150. 150. UIKit UIKit contains all the standard views and controllers which make up your application. • From the time the user taps the application icon to the moment when application execution terminates, UIKit is in charge.
  151. 151. UIKit UIKit contains all the standard views and controllers which make up your application. • From the time the user taps the application icon to the moment when application execution terminates, UIKit is in charge.
  152. 152. UIKit handles the main event loop and calls you when it expects a response. How does it work?
  153. 153. How does the touch screen interface relate to the source code implementation?
  154. 154. Consider the clock application.
  155. 155. What parts make up the clock?
  156. 156. UIKit uses windows and views to fill the screen.
  157. 157. The OS has a window with the status bar on the top. The application window fills the rest of the screen below it.
  158. 158. The window contains the main view for the application.
  159. 159. The view has a tab bar at the bottom and another view for the World Clock.
  160. 160. The World clock has a navigation bar on top. A table view fills the rest.
  161. 161. This table has one cell.
  162. 162. The cell contains four labels and a special clock face. This is how the Clock application is divided into views. Each view is a UIView subclass.
  163. 163. Here, the views are relabed with class names. The status bar is associated with the UIApplication class. The window is a UIWindow. The tab bar is a UITabBar, etc. The cell is a UITableViewCell. The labels are UILabels, and the clock face is some custom UIView.
  164. 164. A viewʼs responsibility is to represent some piece of information or to layout some subviews. UIKit uses controller classes to update and to keep track of views.
  165. 165. A UIApplicationDelegate creates the main window, creates the main view controller, and places the controllerʼs view in the window.
  166. 166. All this happens in the applicationDidFinishLaunching: method of the UIApplicationDelegate.
  167. 167. UIKit has specific controllers for managing certain kinds of views.
  168. 168. A UITabBarController mangages a tab bar. It responds to touches on the bar by displaying the corresponding tab. Each tab has a controller.
  169. 169. This diagram shows a UITabBarController with several view controllers. The title of a controller provides the label for its tab bar button. The controllerʼs tab bar item tells the tab bar controller which image to show on the tab bar button. The selected controllerʼs view fills the space above the tab bar.
  170. 170. In our case, the view is associated with the controller for the World Clock.
  171. 171. Since the World Clock has a navigation bar on top, its controller is a UINavigationController. A navigation controller manages a stack of controllers whose views are pushed in from the right. In the clock, the stack only contains one controller.
  172. 172. So letʼs look at the address book for a minute. When you touch a Johnʼs name, ...
  173. 173. ...his info slides right in. The upper left corner provides a back button.
  174. 174. We have three controllers on the UINavigationContoller stack.
  175. 175. At the top of the stack, in the bottom right corner of the diagram, we see Johnʼs info. His info is pushed on top up of the All Contacts controller, which, in turn, is pushed on top of the Groups controller.
  176. 176. The title of the top controller is used as the title of the navigation bar. The view fills the space under the navigation bar. The navigation item populates the navigation bar with other information including custom bar buttons.
  177. 177. The title of the top controller is used as the title of the navigation bar. The view fills the space under the navigation bar. The navigation item populates the navigation bar with other information including custom bar buttons.
  178. 178. Letʼs return to the Clock.
  179. 179. Notice that the UINavigationController is contained in the UITabBarController.
  180. 180. Whenever you have a tab bar controller and a navigation controller, the tab bar should be on the outside and the navigation controller should be on the inside. Iʼve tried it the other way. It just doesnʼt work: the controllers get very confused.
  181. 181. What controller manages the UITableView?
  182. 182. Why itʼs a UITableViewController. The UITableViewController serves as the data source for the table view. It tells the table how many rows there are and what cell to put in each visible row.
  183. 183. How does the table view controller know what to put in the table? How does it remember the list of clocks? The controller asks the model. I canʼt be sure how Apple wrote the Clock app, but we can imagine what the model is like. Since the clock only needs to keep track of a little data, they shouldnʼt bother with SQLite databases or external property list files.
  184. 184. Instead, they probably store all the data in the user defaults database. What data specifically?
  185. 185. Again, I canʼt be sure, but I guess they use a time zone object.
  186. 186. They need to keep an array of time zones: one for each clock. Since you can add and remove clocks, the array might be mutable.
  187. 187. For each tab in the app, they need to keep some data. So I suppose they use an array for that.
  188. 188. Finally, they could use an index to remember which of the tabs is selected.
  189. 189. Step back. • We have our model, • our view, • and our controller. • Combine them...
  190. 190. Model Step back. • We have our model, • our view, • and our controller. • Combine them...
  191. 191. View Model Step back. • We have our model, • our view, • and our controller. • Combine them...
  192. 192. View Controller Model Step back. • We have our model, • our view, • and our controller. • Combine them...
  193. 193. Step back. • We have our model, • our view, • and our controller. • Combine them...
  194. 194. ...to get our app.
  195. 195. Weʼll be making three apps over the next few days.
  196. 196. Before starting, letʼs finish our overview.
  197. 197. The Cocoa Touch layer contains the primary APIs youʼll use in making apps.
  198. 198. Turn to other layers as needed. Truly, ...
  199. 199. ...the iPhone is an impressive platform.
  200. 200. Objective-C is the language you use to speak to the platform.
  201. 201. History History time.
  202. 202. 1981: Brad Cox Objective-C was developed by Brad Cox in the early eighties.
  203. 203. 1988: NeXT In 1988 NeXT Inc. licensed Objective- C...
  204. 204. NeXTstep ...for their NeXTstep operating system.
  205. 205. 1996: Jobs Returns In 1996 Steve Jobs and NeXT joined Apple.
  206. 206. NeXTstep NeXTstep became...
  207. 207. Mac OS X ...Mac OS X. Letʼs see that again.
  208. 208. NeXTstep NeXTstep became...
  209. 209. Mac OS X ...Mac OS X. One more time.
  210. 210. NeXTstep became...
  211. 211. ...Mac OS X.
  212. 212. Objective-C Objective-C came along for the ride. Since iPhone OS is a version of Mac OS X, the iPhone's programming language is Objective-C.
  213. 213. Design What is Objective-C like?
  214. 214. Objective-C brings some Object-Oriented features from Smalltalk into C.
  215. 215. Runtime Objective-C uses a lightweight runtime library in contrast to the virtual machines of Java and .Net. • Objects are pointers to C structures. • Methods are C functions. • Classes are constructed at runtime.
  216. 216. Runtime • Object ↣ struct objc_object * Objective-C uses a lightweight runtime library in contrast to the virtual machines of Java and .Net. • Objects are pointers to C structures. • Methods are C functions. • Classes are constructed at runtime.
  217. 217. Runtime • Object ↣ struct objc_object * • Method ↣ C Function Objective-C uses a lightweight runtime library in contrast to the virtual machines of Java and .Net. • Objects are pointers to C structures. • Methods are C functions. • Classes are constructed at runtime.
  218. 218. Runtime • Object ↣ struct objc_object * • Method ↣ C Function • Class ↣ Runtime Constructed Objective-C uses a lightweight runtime library in contrast to the virtual machines of Java and .Net. • Objects are pointers to C structures. • Methods are C functions. • Classes are constructed at runtime.
  219. 219. Syntax Objective-C's syntax is the same as C syntax with a few additions.
  220. 220. Directives Directives are prefixed by the at-sign. • These are the ones I type most often. • These, though common, are usually typed by Xcode when you make a new class. • Exceptions arenʼt often caught in Objective-C. They usually represent program errors. • I rarely use any of the directives in this last group.
  221. 221. Directives • @"string literal" @property @synthesize @selector() Directives are prefixed by the at-sign. • These are the ones I type most often. • These, though common, are usually typed by Xcode when you make a new class. • Exceptions arenʼt often caught in Objective-C. They usually represent program errors. • I rarely use any of the directives in this last group.
  222. 222. Directives • @"string literal" @property @synthesize @selector() • @interface @implementation @protocol @class @end Directives are prefixed by the at-sign. • These are the ones I type most often. • These, though common, are usually typed by Xcode when you make a new class. • Exceptions arenʼt often caught in Objective-C. They usually represent program errors. • I rarely use any of the directives in this last group.
  223. 223. Directives • @"string literal" @property @synthesize @selector() • @interface @implementation @protocol @class @end • @dynamic @try @throw @catch() @finally Directives are prefixed by the at-sign. • These are the ones I type most often. • These, though common, are usually typed by Xcode when you make a new class. • Exceptions arenʼt often caught in Objective-C. They usually represent program errors. • I rarely use any of the directives in this last group.
  224. 224. Directives • @"string literal" @property @synthesize @selector() • @interface @implementation @protocol @class @end • @dynamic @try @throw @catch() @finally • @protocol() @private @projected @public @synchronized() @encode() Directives are prefixed by the at-sign. • These are the ones I type most often. • These, though common, are usually typed by Xcode when you make a new class. • Exceptions arenʼt often caught in Objective-C. They usually represent program errors. • I rarely use any of the directives in this last group.
  225. 225. Messages Method calls, also known as messages, use square brackets. • Here the receiver is a variable named “string” and the method name, or selector, is “integerValue”. • Arguments come after a colon. • For multiple arguments, the method name is broken into parts: one for each argument. The selector here is “stringByReplacingOccurrencesOfString:withString:”. In Objective-C, they like descriptive method names. • A method can take a variable number of comma-seperated arguments after its last colon.
  226. 226. Messages • [string integerValue] Method calls, also known as messages, use square brackets. • Here the receiver is a variable named “string” and the method name, or selector, is “integerValue”. • Arguments come after a colon. • For multiple arguments, the method name is broken into parts: one for each argument. The selector here is “stringByReplacingOccurrencesOfString:withString:”. In Objective-C, they like descriptive method names. • A method can take a variable number of comma-seperated arguments after its last colon.
  227. 227. Messages • [string integerValue] • [string isEqualToString:anotherString] Method calls, also known as messages, use square brackets. • Here the receiver is a variable named “string” and the method name, or selector, is “integerValue”. • Arguments come after a colon. • For multiple arguments, the method name is broken into parts: one for each argument. The selector here is “stringByReplacingOccurrencesOfString:withString:”. In Objective-C, they like descriptive method names. • A method can take a variable number of comma-seperated arguments after its last colon.
  228. 228. Messages • [string integerValue] • [string isEqualToString:anotherString] • [string stringByReplacingOccurrencesOfString:oneString withString:anotherString] Method calls, also known as messages, use square brackets. • Here the receiver is a variable named “string” and the method name, or selector, is “integerValue”. • Arguments come after a colon. • For multiple arguments, the method name is broken into parts: one for each argument. The selector here is “stringByReplacingOccurrencesOfString:withString:”. In Objective-C, they like descriptive method names. • A method can take a variable number of comma-seperated arguments after its last colon.
  229. 229. Messages • [string integerValue] • [string isEqualToString:anotherString] • [string stringByReplacingOccurrencesOfString:oneString withString:anotherString] • [NSString stringWithFormat:@"%d %@", number, string] Method calls, also known as messages, use square brackets. • Here the receiver is a variable named “string” and the method name, or selector, is “integerValue”. • Arguments come after a colon. • For multiple arguments, the method name is broken into parts: one for each argument. The selector here is “stringByReplacingOccurrencesOfString:withString:”. In Objective-C, they like descriptive method names. • A method can take a variable number of comma-seperated arguments after its last colon.
  230. 230. Method Declarations Method declarations are similar to message sends. • A minus-sign indicates an instance method. A plus sign would indicate a class method. The return type is placed in parenthesis. • The type of a parameter is wrapped in parenthesis after the colon and before the parameter name. • As with messges, the selector is split when there are multiple parameters. • Hereʼs a class method. The comma and ellipses after the last parameter indicate that the method accepts a variable number of arguments.
  231. 231. Method Declarations • - (NSInteger)integerValue; Method declarations are similar to message sends. • A minus-sign indicates an instance method. A plus sign would indicate a class method. The return type is placed in parenthesis. • The type of a parameter is wrapped in parenthesis after the colon and before the parameter name. • As with messges, the selector is split when there are multiple parameters. • Hereʼs a class method. The comma and ellipses after the last parameter indicate that the method accepts a variable number of arguments.
  232. 232. Method Declarations • - (NSInteger)integerValue; • - (BOOL)isEqualToString:(NSString *)aString; Method declarations are similar to message sends. • A minus-sign indicates an instance method. A plus sign would indicate a class method. The return type is placed in parenthesis. • The type of a parameter is wrapped in parenthesis after the colon and before the parameter name. • As with messges, the selector is split when there are multiple parameters. • Hereʼs a class method. The comma and ellipses after the last parameter indicate that the method accepts a variable number of arguments.
  233. 233. Method Declarations • - (NSInteger)integerValue; • - (BOOL)isEqualToString:(NSString *)aString; • - (NSString *)stringByReplacingOccurrencesOfString: (NSString *)target withString:(NSString *)replacement; Method declarations are similar to message sends. • A minus-sign indicates an instance method. A plus sign would indicate a class method. The return type is placed in parenthesis. • The type of a parameter is wrapped in parenthesis after the colon and before the parameter name. • As with messges, the selector is split when there are multiple parameters. • Hereʼs a class method. The comma and ellipses after the last parameter indicate that the method accepts a variable number of arguments.
  234. 234. Method Declarations • - (NSInteger)integerValue; • - (BOOL)isEqualToString:(NSString *)aString; • - (NSString *)stringByReplacingOccurrencesOfString: (NSString *)target withString:(NSString *)replacement; • + (id)stringWithFormat:(NSString *)format, ...; Method declarations are similar to message sends. • A minus-sign indicates an instance method. A plus sign would indicate a class method. The return type is placed in parenthesis. • The type of a parameter is wrapped in parenthesis after the colon and before the parameter name. • As with messges, the selector is split when there are multiple parameters. • Hereʼs a class method. The comma and ellipses after the last parameter indicate that the method accepts a variable number of arguments.
  235. 235. Dot Syntax • [label text] • [label setText:string] Historically, this is how you would get and set a propery in Objective-C. • But that isnʼt the way itʼs usually done on the iPhone.
  236. 236. Dot Syntax Historically, this is how you would get and set a propery in Objective-C. • But that isnʼt the way itʼs usually done on the iPhone.
  237. 237. Dot Syntax Instead you use a dot for getters and setters. The meaning is the same. The compiled code is the same. Only the notation differs.
  238. 238. Dot Syntax • label.text • label.text = string Instead you use a dot for getters and setters. The meaning is the same. The compiled code is the same. Only the notation differs.
  239. 239. Fast Enumeration for (NSString *name in names) { ... } Last but not least, Objective-C has a special for loop to iterate across collections.
  240. 240. Thatʼs Objective-C in a too-small nutshell. Your printed materials include a concise reference to Objective-C. The materials also include a reference to C and the C Preprocessor.
  241. 241. To summarize: • Your relationship to Apple defines the process of iPhone development. • The SDK provides you with the tools. • The iPhone platform provides you with capabilities. • Objective-C provides you with the language. • These four aspects cover everything you need in order to develop on the iPhone and get those...
  242. 242. To summarize: • Your relationship to Apple defines the process of iPhone development. • The SDK provides you with the tools. • The iPhone platform provides you with capabilities. • Objective-C provides you with the language. • These four aspects cover everything you need in order to develop on the iPhone and get those...
  243. 243. To summarize: • Your relationship to Apple defines the process of iPhone development. • The SDK provides you with the tools. • The iPhone platform provides you with capabilities. • Objective-C provides you with the language. • These four aspects cover everything you need in order to develop on the iPhone and get those...
  244. 244. To summarize: • Your relationship to Apple defines the process of iPhone development. • The SDK provides you with the tools. • The iPhone platform provides you with capabilities. • Objective-C provides you with the language. • These four aspects cover everything you need in order to develop on the iPhone and get those...
  245. 245. To summarize: • Your relationship to Apple defines the process of iPhone development. • The SDK provides you with the tools. • The iPhone platform provides you with capabilities. • Objective-C provides you with the language. • These four aspects cover everything you need in order to develop on the iPhone and get those...
  246. 246. To summarize: • Your relationship to Apple defines the process of iPhone development. • The SDK provides you with the tools. • The iPhone platform provides you with capabilities. • Objective-C provides you with the language. • These four aspects cover everything you need in order to develop on the iPhone and get those...
  247. 247. ...downloads.
  248. 248. The rest of the course is a tutorial in which weʼll build three apps.
  249. 249. Temp We start with a temperature converter. • Weʼll learn all about Interface Builder, • views and controls, • how to use text fields, • alert windows, • landscape autorotation, • and weʼll localize the app.
  250. 250. Temp • Interface Builder We start with a temperature converter. • Weʼll learn all about Interface Builder, • views and controls, • how to use text fields, • alert windows, • landscape autorotation, • and weʼll localize the app.
  251. 251. Temp • Interface Builder • Views & Controls We start with a temperature converter. • Weʼll learn all about Interface Builder, • views and controls, • how to use text fields, • alert windows, • landscape autorotation, • and weʼll localize the app.
  252. 252. Temp • Interface Builder • Views & Controls • Text Fields We start with a temperature converter. • Weʼll learn all about Interface Builder, • views and controls, • how to use text fields, • alert windows, • landscape autorotation, • and weʼll localize the app.
  253. 253. Temp • Interface Builder • Views & Controls • Text Fields • Alerts We start with a temperature converter. • Weʼll learn all about Interface Builder, • views and controls, • how to use text fields, • alert windows, • landscape autorotation, • and weʼll localize the app.
  254. 254. Temp • Interface Builder • Views & Controls • Text Fields • Alerts • Autorotation We start with a temperature converter. • Weʼll learn all about Interface Builder, • views and controls, • how to use text fields, • alert windows, • landscape autorotation, • and weʼll localize the app.
  255. 255. Temp • Interface Builder • Views & Controls • Text Fields • Alerts • Autorotation • Localization We start with a temperature converter. • Weʼll learn all about Interface Builder, • views and controls, • how to use text fields, • alert windows, • landscape autorotation, • and weʼll localize the app.
  256. 256. The Elements Our big example is a viewer for the atomic elements sorted in different ways. • Weʼll learn all about table views, • plists, • view controllers, • table view cells, • web views, • animation, and a whole lot more.
  257. 257. The Elements • Table Views Our big example is a viewer for the atomic elements sorted in different ways. • Weʼll learn all about table views, • plists, • view controllers, • table view cells, • web views, • animation, and a whole lot more.
  258. 258. The Elements • Table Views • Plists Our big example is a viewer for the atomic elements sorted in different ways. • Weʼll learn all about table views, • plists, • view controllers, • table view cells, • web views, • animation, and a whole lot more.
  259. 259. The Elements • Table Views • Plists • View Controllers Our big example is a viewer for the atomic elements sorted in different ways. • Weʼll learn all about table views, • plists, • view controllers, • table view cells, • web views, • animation, and a whole lot more.
  260. 260. The Elements • Table Views • Plists • View Controllers • Table View Cells Our big example is a viewer for the atomic elements sorted in different ways. • Weʼll learn all about table views, • plists, • view controllers, • table view cells, • web views, • animation, and a whole lot more.
  261. 261. The Elements • Table Views • Plists • View Controllers • Table View Cells • Web Views Our big example is a viewer for the atomic elements sorted in different ways. • Weʼll learn all about table views, • plists, • view controllers, • table view cells, • web views, • animation, and a whole lot more.
  262. 262. The Elements • Table Views • Plists • View Controllers • Table View Cells • Web Views • Animation Our big example is a viewer for the atomic elements sorted in different ways. • Weʼll learn all about table views, • plists, • view controllers, • table view cells, • web views, • animation, and a whole lot more.
  263. 263. GLGravity As a final treat, weʼll play with • OpenGL ES • and the iPhoneʼs accelerometer.
  264. 264. GLGravity • OpenGL ES As a final treat, weʼll play with • OpenGL ES • and the iPhoneʼs accelerometer.
  265. 265. GLGravity • OpenGL ES • Accelerometer As a final treat, weʼll play with • OpenGL ES • and the iPhoneʼs accelerometer.
  266. 266. These are our three examples.
  267. 267. Let’s get started. Letʼs get started.

×