How learn Objective C

how to learn objective c for beginners and Lecture Notes in OBJECTIVE-C pdf free downlaod
AndyCole Profile Pic
AndyCole,United Kingdom,Professional
Published Date:09-07-2017
Your Website URL(Optional)
Comment
INTRODUCTION TO OBJECTIVE-C CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 12 — 09/29/2011 © Kenneth M. Anderson, 2011 1History (I) Brad Cox created Objective-C in the early 1980s It was his attempt to add object-oriented programming concepts to the C programming language NeXT Computer licensed the language in 1988; it was used to develop the NeXTSTEP operating system, programming libraries and applications for NeXT In 1993, NeXT worked with Sun to create OpenStep, an open specification of NeXTSTEP on Sun hardware © Kenneth M. Anderson, 2011 3History (II) In 1997, Apple purchased NeXT and transformed NeXTSTEP into MacOS X which was first released in the summer of 2000 Objective-C has been one of the primary ways to develop applications for MacOS for the past 11 years In 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 TV © Kenneth M. Anderson, 2011 4Objective-C is “C plus Objects” (I) Objective-C makes a small set of extensions to C which turn it into an object-oriented language It is used with two object-oriented frameworks The Foundation framework contains classes for basic concepts such as strings, arrays and other data structures and provides classes to interact with the underlying operating system The AppKit contains classes for developing applications and for creating windows, buttons and other widgets © Kenneth M. Anderson, 2011 5Objective-C is “C plus Objects” (II) Together, Foundation and AppKit are called Cocoa On iOS, AppKit is replaced by UIKit Foundation and UIKit are called Cocoa Touch In this lecture, we focus on the Objective-C language, we’ll see a few examples of the Foundation framework we’ll see examples of UIKit in Lecture 13 © Kenneth M. Anderson, 2011 6C Skills? Highly relevant Since Objective-C is “C plus objects” any skills you have in the C language directly apply statements, data types, structs, functions, etc. What the OO additions do, is reduce your need on structs, malloc, dealloc and the like and enable all of the object-oriented concepts we’ve been discussing Objective-C and C code otherwise freely intermix © Kenneth M. Anderson, 2011 7Development Tools (I) Apple’s XCode is used to develop in Objective-C Behind the scenes, XCode makes use of either gcc or Apple’s own LLVM to compile Objective-C programs The latest version of Xcode, Xcode 4, has integrated functionality that previously existed in a separate application, known as Interface Builder We’ll see examples of that integration next week © Kenneth M. Anderson, 2011 8Development Tools (II) XCode is available on the Mac App Store It is free for users of OS X Lion Otherwise, I believe it costs 5 for previous versions of OS X Clicking Install in the App Store downloads a program called “Install XCode”. You then run that program to get XCode installed © Kenneth M. Anderson, 2011 9Hello World As is traditional, let’s look at our first objective-c program via the traditional Hello World example To create it, we launch XCode and create a New Project select Application under the MacOS X select Command Line Tool on the right (click Next) select Foundation and type “Hello World” (click Next) select a directory, select checkbox for git (click Finish) © Kenneth M. Anderson, 2011 10Step One © Kenneth M. Anderson, 2011 11Step Two © Kenneth M. Anderson, 2011 12Step Two © Kenneth M. Anderson, 2011 13Similar to what we saw with Eclipse, XCode creates a default project for us; There are folders for this program’s source code (.m and .h files), frameworks, 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 yet © Kenneth M. Anderson, 2011 14Exciting, 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 gdb You can hide gdb’s output by switching the pop-up menu in the upper left to “Target Output” © Kenneth M. Anderson, 2011 15The resulting project structure on disk does not map completely to what is shown in Xcode; The source file, man page, and pre-compiled header file are all stored in a sub-directory of the main directory. The project file HelloWorld.xcodeproj is stored in the main directory. It is the file that keeps track of all project settings and the location of project files. XCode project directories are a lot simpler now that files generated during a build are stored elsewhere. © Kenneth M. Anderson, 2011 16Where is the actual application? After you ran the application, HelloWorld switched from being displayed in red to being displayed in black You can right click on HelloWorld and select “Show in Finder” to see where XCode placed the actual executable By default, XCode creates a directory for your project in /Library/Developer/XCode/DerivedData For HelloWorld, XCode generated 20 directories containing 31 files © Kenneth M. Anderson, 2011 17Why so many files and directories? In addition to the actual results of compiling the source code, XCode stores in DerviedData Logs and Indexes (for code autocomplete feature) Build information, including .o files, precompiled headers, debug information, etc. The actual executable was located at /Library/Developer/Xcode/DerivedData/HelloWorld- dotwnmcnqdjnnigmgnesuacnsxfh/Build/Products/Debug © Kenneth M. Anderson, 2011 18The resulting executable can be executed from the command line, fulfilling the promise that we were creating a command-line tool As you can see, most of the text on Slide 15 was generated by gdb… our command line tool doesn’t do much but say hi to the world. Note the “2011-09-24 14:43:01.336 HelloWorld4900:707” is generated by a function called NSLog() as we’ll see next © Kenneth M. Anderson, 2011 19Objective-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 once Ignore the “NSAutoreleasePool” stuff for now Thus our program calls a function, NSLog, and returns 0 The blue arrow indicates that a breakpoint has been set; gdb will stop execution on line 7 the next time we run the program © Kenneth M. Anderson, 2011 20gdb is integrated into XCode; here gdb is stopped at our breakpoint; this is XCode 3, XCode 4 looks similar © Kenneth M. Anderson, 2011 21