Objective-C Quinton Palet. Introduction  Objective-C was developed to bring large scale software development the power of the object-oriented approach.

Slides:



Advertisements
Similar presentations
Lecture 2 - Introduction Objective C is used primarily for application development on Apple's Mac OS X and iPhone. On the Apple it is used together with.
Advertisements

Objective-C Lecture 2 Memory management Memory management in OC is semi- automatic: The programmer must allocate memory for objects either a) explicitly.
Introduction to Java 2 Programming Lecture 3 Writing Java Applications, Java Development Tools.
Compiler Design PROJECT PRESENTATION : COMPILER FOR OBJECTIVE C Harshal Waghmare Jeet Kumar Nandan Kumar Vishal Agrawal.
Introduction to Objective-C and Xcode (Part 1) FA 175 Intro to Mobile App Development.
CS 3800 Su 11 Beg. IOS Dev L4 Obj C part 1 CS 3800 Introduction to IOS programming Summer 2011 G. Zimmerman.
Road Map Introduction to object oriented programming. Classes
IPhone Development Crash Course By Dylan Harris
IPhone Development JaxCodeCamp Who am I David Fekke.NET Developer, ColdFusion Work at LPS Presenter JaxDug, JaxJug, JSUG & JaxFusion Mac User 1986.
Scott Grissom, copyright 2004Ch 3: Java Features Slide 1 Why Java? It is object-oriented provides many ready to use classes platform independent modern.
Terms and Rules Professor Evan Korth New York University (All rights reserved)
1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation –The new operator –The delete operator –Dynamic.
Friday, August 29, 2014 CSCI 351 – Mobile Applications Development.
Handybook: Swift Jayant Sani. Handybook Opinions “It’s like Ruby on Rails, for iOS!” – Nikita “A function should only do one thing and return.
1 Procedural Concept The main program coordinates calls to procedures and hands over appropriate data as parameters.
UFCFX5-15-3Mobile Device Development UFCFX Mobile Device Development An Introduction to the Module.
Comparison of OO Programming Languages © Jason Voegele, 2003.
CSSE501 Object-Oriented Development. Chapter 5: Messages, Instances and Initialization  This chapter examines OOP run-time features: Object Creation.
IOS WorkShoP Xcode 4 iOS 5 : “A Primer”. Objective-C iOS applications are written in Objective-C language using the Cocoa Touch library Objective-C is.
Programming Languages and Paradigms Object-Oriented Programming.
C++ Programming. Table of Contents History What is C++? Development of C++ Standardized C++ What are the features of C++? What is Object Orientation?
More on Classes Inheritance Copyright © 2012 by Yong-Gu Lee
FINAL PRESENTATION SYDNEY TOUR. Divya Nalla Raja Kandasamy RajaShekar Donti Ren Zhu Sadah Omar Sulaiman
Object Oriented Programming
By Noorez Kassam Welcome to JNI. Why use JNI ? 1. You already have significantly large and tricky code written in another language and you would rather.
Objective C Basics. It’s C with Some Extras!  Cross Platform language  Mac  Linux/UNIX  Windows  Layer above C (Superset)  Adds Object-Oriented.
OS X Development Tom Schroeder. Table of Contents Who cares? HistoryObjective-CCocoaEnvironmentDesign.
Chapter 3.5 Memory and I/O Systems. 2 Memory Management Memory problems are one of the leading causes of bugs in programs (60-80%) MUCH worse in languages.
Objective-C First Part adapted from a presentation by Kevin Layer.
Objective-C OOP Spring OOP Conceptually the same as C++, Java, and all other object oriented languages The syntax, however… …is, well, different.
Folio3 IPhone Training Session 1 Presenter: Imam Raza.
Mobile Device Programming
1 Introduction to Objective-C Programming (Level: Beginner) Lecture 1.
Introduction to Building Windows 8.1 & Windows Phone Applications.
Objective-C1 CS151 Presentation: Objective C Kai Tai Pang William Sze.
Chapter 13. Procedural programming vs OOP  Procedural programming focuses on accomplishing tasks (“verbs” are important).  Object-oriented programming.
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
Prepared by: Elsy Torres Shajida Berry Siobhan Westby.
C# EMILEE KING. HISTORY OF C# In the late 1990’s Microsoft recognized the need to be able to develop applications that can run on multiple operating system.
View Controllers Content taken from book: “iPhone SDK Development” by Bill Dudney and Chris Adamson.
Monday, August 31, 2015 CSCI 351 – Mobile Applications Development.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
Objective-C Memory management Memory management is semi-automatic: The programmer must allocate memory for objects either a) explicitly (alloc) or b) indirectly.
Introduction to C#. Why C#? Develop on the Following Platforms ASP.NET Native Windows Windows 8 / 8.1 Windows Phone WPF Android (Xamarin) iOS (Xamarin)
Polymorphism, Dynamic Typing, and Dynamic Binding Copyright © 2012 by Yong-Gu Lee
Objective-C Drew Cheng CS420. Overview True superset of ANSI C Object-Oriented methods from SmallTalk There is no formal written standard for the language.
Object-Oriented Programming Chapter Chapter
Monday, August 31, 2012 CSCI 333 – Systems Programming.
Object Oriented Software Development 4. C# data types, objects and references.
Introduction to Objective-C Spring Goals An introduction to Objective-C As implemented by the Apple LLVM Compiler 4.0 (a.k.a. Clang) Only the basics…
The iOS Platform and SDK. iOS iPhoneiPad Mini iPad.
Lec 5 Obj-C part 2 CS 3800 Introduction to IOS programming Lecture 5 Summer 2011.
Classes, Interfaces and Packages
Introduction To Java Programming 1.0 Basic Concepts of Java Programming 2.0 Classes, Polymorphism and Inheritance 3.0 Exception handling 4.0.
© 2004 Pearson Addison-Wesley. All rights reserved January 23, 2006 Creating Objects & String Class ComS 207: Programming I (in Java) Iowa State University,
Objective-C: Intro Michelle Alexander COMS E6998 2/4/2013.
1 n Object Oriented Programming. 2 Introduction n procedure-oriented programming consists of writing a list of instructions and organizing these instructions.
© 2004 Pearson Addison-Wesley. All rights reserved September 5, 2007 Packages & Random and Math Classes ComS 207: Programming I (in Java) Iowa State University,
Best 5 Mobile App Development Tools for Developer's to think beyond the Limitation.
Object Lifetime and Pointers
C# for C++ Programmers 1.
CSCI 351 – Mobile Applications Development
Introduction to Objective-C
CSCI 351 – Mobile Applications Development
CSC 581: Mobile App Development
Pointers, Dynamic Data, and Reference Types
From C++ to Java Java history: Oak, toaster-ovens, internet language, panacea What it is O-O language, not a hybrid (cf. C++) compiled to byte-code, executed.
EEC-492/693/793 iPhone Application Development
Introduction to Data Structure
Java Programming Language
Presentation transcript:

Objective-C Quinton Palet

Introduction  Objective-C was developed to bring large scale software development the power of the object-oriented approach  Comprised of C and Smalltalk  Strict superset of C

History  Early 1980’s – Brad Cox and Tom Love develop Objective-C at Stepstone  1985 – Steve Jobs leaves Apple and starts NeXT  1986 – Stepstone releases Objective-C  1988 – Steve Jobs licensed Objective-C for NeXT  1996 – Apple buys NeXT  1999 – Apple releases OS X  2007 – Apple releases iOS and Objective-C 2.0

Growing Popularity  From 5 th to 3 rd on the TIOBE programming community index  Apple gaining more market share in PC market  iPhone, iPad, iPod Touch, and Apple TV 

Environments  Windows  GCC under Cygwin or MinGW  Linux  GNU compiler  Mac  Xcode

Frameworks  Collection of classes  Provide methods beyond the core methods  Frameworks often contain other Frameworks

Cocoa & Cocoatouch  Most popular frameworks  Cocoa  Foundation framework  CoreData framework  AppKit framework  Cocoatouch  Foundation framework  CoreData framework  UIKit framework

File Declarations  Declared by file type .h Interface .m Implementation .nm Implementation with C++ code along with Objective-C and C code

Syntax  Strict superset of C  Can compile C code without any linkage  Commenting the same  // single line  /* block */

Data types and Variable  Objective-C by itself has  Int  Float  Double  Char  BOOL  With frameworks has access to much more  Objective-C 2.0 Added  Int (signed/unsigned)  Short  Long  Long Long  Id

Data types and Variables cont.  Using Foundation.framework you can define a string: NSString *someString world”;  * represents that it is a pointer NSString *SecondString = [[NSString alloc] self.name];

Syntax - Functions  Declare method in interface file or.h + (return_type) classMethod1; -(return_type) classMethod2: (param1_type) param1_name; + similar to a static function in Java - similar function called on instance of class - (void)insertObject: (id)someObject atIndex: (int) index;

Syntax – Functions cont.  Implementation similar to C++ using the interface declaration  Done in the.m or.nm file + (return_type) classMethod: (paramType) paramName { Return (return_type) returnName; }

Functions cont.  Objective-C does not allow for Function overloads  This makes it so Objective-C isn’t able to easily implement polymorphism  Where as Java can implement constructors like: public initPerson(){ name = DEFAULTNAME; } Public initPerson(String inName){ name = inName; }

Functions Cont.  In order to do this in Objective-C you would have to implement different method names like: -(void) initPerson { name = [[NSString alloc] initWithString:DEFAULTNAME]; } -(void) initPersonWithName: (NSString *) inName{ name = [[NSString alloc] initWithString: inName]; }

Functions Cont.  Objective-C does not allow for Operator overloads  In turn Objective-C does not allow ad-hoc polymorphism  Example in C++ or C#: Time Time::operator+(const Time& addTime) { Time temp = *this; temp.seconds += addTime.seconds; temp.minutes += temp.seconds / 60; temp.seconds %= 60; temp.minutes += addTime.minutes; temp.hours += temp.minutes / 60; temp.minutes %= 60; temp.hours += addTime.hours; return temp; }  Allows you to do: sumTime = firstTime + secondTime;

Functions Cont.  Simple Solution make a function that does what you would want the operator overload to do. -(void) addTime: (Time) inTime{ self.seconds += inTime.seconds; self.minutes += self.seconds / 60; self.seconds %= 60; self.minutes += inTime.minutes; self.hours += self.minutes / 60; self.minutes %= 60; self.hours += inTime.hours; } So can be called by [timeOne addTime: timeTwo];

Messages  Messages are similar to a method call in C++ or Java Object *O = [Object messagePassed: Param];  Message passing allows dynamic typing  Allows postponing a messages destination until runtime  If class can’t handle the message it can forward it, hold onto it, or silently ignore it - (void) setValue: (id) Obj;  Obj can be any class

Memory Management  No built in memory management  Must allocate or alloc memory for objects NSString str = [[NSString alloc] init];  Can retain memory to pass objects NSString str = [[[NSString alloc] init] retain];  Developer responsible for releasing objects [str release];

Memory Management  Autoreleasepool allows you to group objects and release them all at once or “drain” the pool NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; // create autoreleased objects NSString str = [[[NSString alloc] init] autorelease]; [pool release];

Objective-C 2.0  Added in  Garbage collection  Modern runtime  Fast enumeration Replaced: NSEnumerator *enumerator = [someCollection objectEnumerator]; someObject *O While ((O = [enumerator nextObject]) != nil) { [O name]; } With: for( someObject *O in someCollection) { name]; }  dot syntax Without dot syntax: [someClass objectAt: 0 With dot syntax:someClass[0].name

Objective-C 2.0 cont.  Added in Property variables Can be implemented or (nonatomic) propertyType * (nonatomic, readonly, getter = timestamp) propertyType * propertyName2;

Objective-C 2.0 cont. So (nonatomic) propertyType * (nonatomic, readonly, getter = propertyName) propertyType * propertyName2; Turns into Event{ propertyType * propertyName; propertyType * propertyName2; Event{ -(propertyType) propertyName{ return propertyName; } -(void) setPropertyName: (propertyType) in { _propertyName = in; } -(propertyType)propertyName2{ return [self propertyName]; }

Objective-C 2.0 cont.  You can choose to dynamically do your properties getter and setter methods also, for (nonatomic) propertyType propertyName; propertyName; // need this because it lets the compiler know you will implement // your own getter and setter methods for the property -(propertyType) propertyName { return propertyName; } -(void) setPropertyName: (propertyType) inValue { propertyName += inValue; }

Automatic Reference Counting  Garbage collection was deprecated  Developer no longer needs to manually manage retain and release  Retain and release added in by compiler at compile time  Removed the overhead of a separate process managing retain counts

Objective-C or Java  Both have benefits to learning them, and are the two of the most popular languages for mobile development.  Both are in the top 4 of the TIOBE index  Java has a written standard  Objective-C has no written standard but is heavily documented by Apple  Java is supported on more devices where as Objective-C is primarily Apple devices.  Java has IDEs for all major operating systems where as Objective-C is only on Mac OS X

Objective-C or Java cont.  Objective-C can be more readable than Java  Objective-C is a more dynamic language  Allows you to easily add onto programs due to dynamic typing  Objective-C programs tend to be larger due to compiler not being able to strip methods or make them inline because of the dynamic typing you wont know what methods are needed until runtime.  Objective-C does not allow operator overloading, function overloading, and multiple inheritance.  Objective-C doesn’t waste resources on a garbage collector  In order to add an Objective-C app to their marketplace it must go through a screening and you need a developers license, Java has open marketplaces and also requires no developers license

Objective-C or Java cont.  Overall I would say Java is a more useful language to learn rather than Objective-C  Doesn’t mean there’s no benefit to learning Objective-C  Apple has a large market share in PC, mobile phones, and tablets.  You can use other languages to develop for OS X and iOs  Such as C++ and Ruby  Many times still need to use the Cocoa framework to add the necessary functionality  Makes it so you’re still developing in Objective-C and only adding another layer in below the application making it less efficient

For more Information on Objective-C 

Questions ?

References  [1] Kaul, Vivek. (2009, May 11). What Jobs did when he was fired from Apple. Retrieved from apple_  [2] Biancuzzi, F., & Warden, S. (2009). Masterminds of programming: Conversations with the creators of major programming languages. Sepastopol, CA: O'Reilly Media.  [3] Apple. (2010, December 13). Cocoa fundamentals guide. Retrieved from mentals/Introduction/Introduction.html  [4] Apple. (2011, October 12). The objective-c programming language. Retrieved from ntroduction/introObjectiveC.html  [5] LLVM. (2012). Automatic Reference Counting. Retrieved from  [6] TIOBE Software. (2012, November). TIOBE programming community index for November Retrieved from