Unformatted text preview:

© Kenneth M. Anderson, 2011INTRODUCTION TO OBJECTIVE-CCSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGNLECTURE 12 — 02/17/20111Thursday, February 17, 2011© Kenneth M. Anderson, 2011Goals of the LecturePresent an introduction to Objective-C 2.0Coverage of the language will be INCOMPLETEWe’ll see the basics… there is a lot more to learn2Thursday, February 17, 2011© Kenneth M. Anderson, 2011History (I)Brad Cox created Objective-C in the early 1980sIt was his attempt to add object-oriented programming concepts to the C programming languageNeXT Computer licensed the language in 1988; it was used to develop the NeXTSTEP operating system, programming libraries and applications for NeXTIn 1993, NeXT worked with Sun to create OpenStep, an open specification of NeXTSTEP on Sun hardware3Thursday, February 17, 2011© Kenneth M. Anderson, 2011History (II)In 1997, Apple purchased NeXT and transformed NeXTSTEP into MacOS X which was first released in the summer of 2000Objective-C has been one of the primary ways to develop applications for MacOS for the past 11 yearsIn 2008, it became the primary way to develop applications for iOS targeting (currently) the iPhone and the iPad and (soon, I’m guessing) the Apple TV4Thursday, February 17, 2011© Kenneth M. Anderson, 2011Objective-C is “C plus Objects” (I)Objective-C makes a small set of extensions to C which turn it into an object-oriented languageIt is used with two object-oriented frameworksThe Foundation framework contains classes for basic concepts such as strings, arrays and other data structures and provides classes to interact with the underlying operating systemThe AppKit contains classes for developing applications and for creating windows, buttons and other widgets5Thursday, February 17, 2011© Kenneth M. Anderson, 2011Objective-C is “C plus Objects” (II)To g e t h e r, F o u n d a t i o n a n d A p p K i t a r e c a l l e d C o c o aOn iOS, AppKit is replaced by UIKitFoundation and UIKit are called Cocoa TouchIn this lecture, we focus on the Objective-C language,we’ll see a few examples of the Foundation frameworkwe’ll see examples of UIKit in Lecture 136Thursday, February 17, 2011© Kenneth M. Anderson, 2011C Skills? Highly relevantSince Objective-C is “C plus objects” any skills you have in the C language directly applystatements, data types, structs, functions, etc.What the OO additions do, is reduce your need onstructs, malloc, dealloc and the likeand enable all of the object-oriented concepts we’ve been discussingObjective-C and C code otherwise freely intermix7Thursday, February 17, 2011© Kenneth M. Anderson, 2011Development Tools (I)Apple provides XCode and Interface Builder to develop programs in Objective-CBehind the scenes, XCode makes use of gcc to compile Objective-C programsIn a future version of XCode, to be released shortly, Interface Builder will go away as a separate applicationIts functionality will be merged into XCodeWe’ll see examples of Interface Builder next week8Thursday, February 17, 2011© Kenneth M. Anderson, 2011Development Tools (II)XCode and Interface Builder comes with Snow Leopard on the Development Tools DVDIt is also available for download at <http://developer.apple.com/>Yo u n e e d t o r e g i s t e r i n A p p l e ’s d e ve l o p m e n t p r o g r a m but registration is freeTo i n s t a l l : d o u bl e c l i c k t h e d ow n l o a d e d . d m g fi l e a n d t h e n double click the installer and follow instructions9Thursday, February 17, 2011© Kenneth M. Anderson, 2011Hello WorldAs is traditional, let’s look at our first objective-c program via the traditional Hello World exampleTo c r e a t e i t , w e l a u n c h X C o d e a n d c r e a t e a N e w P r o j e c tIn the resulting dialog (see next slide)select Application under the MacOS Xselect Command Line Tool on the rightselect Foundation from the pop-up menuclick Choose and select a location for the project10Thursday, February 17, 2011© Kenneth M. Anderson, 201111Thursday, February 17, 2011© Kenneth M. Anderson, 201112Similar to what we saw with Eclipse, XCode creates a default project for us;There are folders for this command line program’s source code (.m files), documentation, external dependencies and products (the application itself)Note: the Foundation framework is front and center and HelloWorld is shown in red because it hasn’t been created yetThursday, February 17, 2011© Kenneth M. Anderson, 201113Exciting, isn’t it. The template is ready to run; clicking “Build and Run” brings up a console that shows “Hello, World!” being displayed; One interesting thing to note is that the program is being run by gdbThursday, February 17, 2011© Kenneth M. Anderson, 201114The resulting project structure on disk does not map completely to what is shown in Xcode; The source file, man page, project file, and pre-compiled header file are all in the same directory;A lot of stuff gets generated when you buildThursday, February 17, 2011© Kenneth M. Anderson, 201115The resulting executable can be executed from the command line, fulfilling the promise that we were creating a command-line toolAs you can see, most of the text on Slide 11 was generated by gdb… our command line tool doesn’t do much but say hi to the world.Note the “2011-02-17 08:51:21.023 HelloWorld[41071:903]” is generated by a function called NSLog() as we’ll see nextThursday, February 17, 2011© Kenneth M. Anderson, 201116Objective-C programs start with a function called main, just like C programs; #import is similar to C’s #include except it ensures that header files are only included once and only onceIgnore the “NSAutoreleasePool” stuff for nowThus our program calls a function, NSLog, and returns 0The blue arrow indicates that a breakpoint has been set; gdb will stop execution on line 7 the next time we run the programThursday, February 17, 2011© Kenneth M. Anderson, 201117gdb is integrated into XCode; here we see the program stopped at our breakpoint; variables can be viewed in the upper right Thursday, February 17, 2011© Kenneth M. Anderson, 201118Let’s add objects…Note: This example comes from “Learning Objective-C 2.0: A Hands-On Guide to Objective-C for Mac and iOS Developers” written by Robert ClairIt is an excellent book that I highly recommendHis review of the C language is an excellent bonus to the content on Objective-C itselfWe’re


View Full Document

CU-Boulder CSCI 5448 - INTRODUCTION TO OBJECTIVE-C

Documents in this Course
Django

Django

42 pages

ENRS

ENRS

30 pages

PhoneGap

PhoneGap

22 pages

Load more
Download INTRODUCTION TO OBJECTIVE-C
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view INTRODUCTION TO OBJECTIVE-C and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view INTRODUCTION TO OBJECTIVE-C 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?