Introduction to Objective c

4,030 views

Published on

This Presentation gives a brief introduction to Objective C language. It is intended for audience already familiar to programming concepts and intends to familiarize audience with the syntax of the language.

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

No Downloads
Views
Total views
4,030
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
0
Comments
0
Likes
9
Embeds 0
No embeds

No notes for slide

Introduction to Objective c

  1. 1. OBJECTIVE – CRohit Sharma
  2. 2. Objective-C Initially written as a preprocessor for C to add some capabilities of Smalltalk Objective-C is thin layer on top of C Syntax:  For non-object-oriented operations: identical to C  For object-oriented features: similar to Smalltalk
  3. 3. Data Types Primitive types similar to that of C Type Definition id Pointer to data structure of object SEL A null-terminated string representing method’s name IMP A pointer to a method implementation BOOL A Boolean value, either YES or NO
  4. 4. Classes Objective-C class definitions are seprated into an interface and an implementation part Usually defined in separate .h and .m files
  5. 5. Defining the class interface @interface BankAccount : NSObject { float accountBalance; NSString *accountNumber; } -(float)withDraw: (float)amount; -(void)deposit: (float)amount; @end
  6. 6. Defining the class interface @interface BankAccount : NSObject { float accountBalance; NSString *accountNumber; } -(float)withDraw: (float)amount; -(void)deposit: (float)amount; @end
  7. 7. Defining the class interface @interface BankAccount : NSObject { float accountBalance; NSString *accountNumber; } -(float)withDraw: (float)amount; -(void)deposit: (float)amount; @end
  8. 8. Defining the class interface @interface BankAccount : NSObject { float accountBalance; NSString *accountNumber; } -(float)withDraw: (float)amount; -(void)deposit: (float)amount; @end
  9. 9. Defining the classimplementation#import “BankAccount.h”@implementation BankAccount- (float)withDraw: (float)amount { // calculations return amount;}-(void)deposit: (float)amount{ //record transaction}@end
  10. 10. Defining the classimplementation#import “BankAccount.h”@implementation BankAccount- (float)withDraw: (float)amount { // calculations return amount;}-(void)deposit: (float)amount{ //record transaction}@end
  11. 11. Methods & Messages Methods are always public by default. Methods are invoked by passing messages…. Simple messages: [object message]; Messages with arguments:  A method name can be split into several segments [object messageWithArg1:arg1 AndArg2:arg2];
  12. 12. Creating Objects Java:  BankAccount account = new BankAccount(); Objective-C:  BankAccount *account = [[BankAccount alloc] init];
  13. 13. Properties - Decleration Shorthand for accessors / setters-getters@interface Test0 : NSObject { int iVar;}@property (readwrite) int iVar;@end @property Declares the accessors
  14. 14. Properties - Implementation@implementation Test0@synthesize iVar; //code@end @synthesize : implements the accessor methods  set<PropertyName>  <propertyName>
  15. 15. COCOAAN INTRODUCTION
  16. 16. Introduction Set of object-oriented APIs Composed of two object-oriented frameworks:  Foundation framework:  Provide basic functionalities not impacting UI  Application Kit:  Built on Foundation classes  Provides for handling UI events
  17. 17. MVC Architecture M-V-C : Model – View – Controller Isolates LOGIC from USER INTERFACE
  18. 18. GUI in Cocoa Nib / Xib Files  An archive of objects serialized to disk  Not generated code  Can contain Application windows and other UI objects Outlets:  Special instance variables containing reference to other objects.  An object can communicate with other objects sending messages to them through outlets
  19. 19. GUI in Cocoa Actions  Actions are special methods which are triggered by user-interface objects  Indicated with IBAction keyword
  20. 20. DemoA Currency Converter
  21. 21. Steps Create the interface Define the Classes Connect Model , Controller and View Implement the Classes Build and Run

×