SlideShare a Scribd company logo
1 of 35
Session - 2




Presented By: A.T.M. Hassan Uzzaman
Agendas

 OOP Concepts in Objective-c
 Delegates and callbacks in Cocoa touch
 Table View, Customizing Cells
 PList (Read, write)
Obj-C vs C#
           Obj-C                                C#
 [[object method] method];           obj.method().method();
       Memory Pools                   Garbage Collection
             +/-                         static/instance
             nil                                null
(void)methodWithArg:(int)value {}   void method(int value) {}
            YES NO                          true false
           @protocol                         interface
Classes from Apple (and some history)
 NSString is a string of text that is immutable.
 NSMutableString is a string of text that is mutable.
 NSArray is an array of objects that is immutable.
 NSMutableArray is an array of objects that is
  mutable.
 NSNumber holds a numeric value.
Objective-C Characteristics and
Symbols
 Written differently from other languages
 Object communicate with messages—does not “call” a
  method.
 @ indicates a compiler directive. Objective-C has own
  preprocessor that processes @ directives.
 # indicates a preprocessor directive. Processes any #
  before it compiles.
Declare in Header file (.h)
Each method will start with either a – or a + symbol.
  - indicates an instance method (the receiver is an
  instance)
  +indicates a class method (the receiver is a class name)
Example of a instance method
-(IBAction)buttonPressed:(id)sender;
Or with one argument
-(void)setFillColor:(NSColor*) newFillColor;
Parts of a Method in a Class
 Implement the method in the .m file
 Example:
-(IBAction)buttonPressed:(id)sender{
do code here….
}
 Example 2:
-(void) setOutlineColor:(NSColor*) outlineColor{
  do code here….
}
Class Declaration (Interface)
                                     Node.h
#import <Cocoa/Cocoa.h>
@interface Node : NSObject {
        Node *link;
        int contents;
                                 Class is Node who’s parent is
}                                NSObject
+(id)new;
                                 {   class variables }
-(void)setContent:(int)number;
-(void)setLink:(Node*)next;
-(int)getContent;                +/- private/public methods of Class
-(Node*)getLink;
@end
                                 Class variables are private
Class Definition (Implementation)
#import “Node.h”
@implementation Node                Node.m
+(id)new
          { return [Node alloc];}
-(void)setContent:(int)number
          {contents = number;}
-(void)setLink:(Node*)next {
          [link autorelease];
          link = [next retain];     Like your C++ .cpp
}                                   file
-(int)getContent
          {return contents;}
-(Node*)getLink                     >>just give the
          {return link;}            methods here
@end
Creating class instances
Creating an Object
    ClassName *object = [[ClassName alloc] init];
    ClassName *object = [[ClassName alloc] initWith* ];
         NSString* myString = [[NSString alloc] init];
         Nested method call. The first is the alloc method called on NSString itself.
            This is a relatively low-level call which reserves memory and instantiates an
            object. The second is a call to init on the new object. The init implementation
            usually does basic setup, such as creating instance variables. The details of
            that are unknown to you as a client of the class. In some cases, you may use a
            different version of init which takes input:



    ClassName *object = [ClassName method_to_create];
         NSString* myString = [NSString string];
         Some classes may define a special method that will in essence call alloc followed by some
          kind of init
Reference [[Person alloc] init];action
Person *person =
                 counting in
 Retain count begins at 1 with +alloc
[person retain];
 Retain count increases to 2 with -retain
[person release];
 Retain count decreases to 1 with -release
[person release];
 Retain count decreases to 0, -dealloc automatically
called
Autorelease
 Example: returning a newly created object
-(NSString *)fullName
{
  NSString *result;
  result = [[NSString alloc] initWithFormat:@“%@
%@”, firstName, lastName];

    [result autorelease]

    return result;
}
Method Names & Autorelease
 Methods whose names includes alloc, copy, or new return a retained
  object that the caller needs to release

NSMutableString *string = [[NSMutableString alloc] init];
// We are responsible for calling -release or -autorelease
[string autorelease];

 All other methods return autoreleased objects

NSMutableString *string = [NSMutableString string];
// The method name doesn’t indicate that we need to release
it, so don’t

 This is a convention- follow it in methods you define!
Polymorphism
 Just as the fields of a C structure are in a protected
  namespace, so are an object’s instance variables.
 Method names are also protected. Unlike the names of
  C functions, method names aren’t global symbols. The
  name of a method in one class can’t conflict with
  method names in other classes; two very different
  classes can implement identically named methods.
 Objective-C implements polymorphism of method
  names, but not parameter or operator overloading.
Inheritance




 Class Hierarchies
 Subclass Definitions
 Uses of Inheritance
protocol
Protocol (Continue..)
Categories
Categories (Continue..)
Categories (Continue..)
NSDictionary
 Immutable hash table. Look up objects using a key to get a
   value.
+ (id)dictionaryWithObjects:(NSArray *)values forKeys:(NSArray *)keys;
+ (id)dictionaryWithObjectsAndKeys:(id)firstObject, ...;
 Creation example:
NSDictionary *base = [NSDictionary dictionaryWithObjectsAndKeys:
                          [NSNumber numberWithInt:2], @“binary”,
                          [NSNumber numberWithInt:16], @“hexadecimal”, nil];
 Methods
              - (int)count;
              - (id)objectForKey:(id)key;
              - (NSArray *)allKeys;
              - (NSArray *)allValues;
see documentation (apple.com) for more details
NSMutableDictionary
 Changeable
+ (id)dictionaryWithObjects:(NSArray *)values forKeys:(NSArray *)keys;
+ (id)dictionaryWithObjectsAndKeys:(id)firstObject, ...;

 Creation :
+ (id)dictionary; //creates empty dictionary
 Methods
- (void)setObject:(id)anObject forKey:(id)key;
- (void)removeObjectForKey:(id)key;
- (void)removeAllObjects;
- (void)addEntriesFromDictionary:(NSDictionary *)otherDictionary;


see documentation (apple.com) for more details
We will see this in

Property list (plist)                                            practice later


 A collection of collections
 Specifically, it is any graph of objects containing only the following classes:
          NSArray, NSDictionary, NSNumber, NSString, NSDate, NSData

 Example1 : NSArray is a Property List if all its members are too
     NSArray of NSString is a Property List
     NSArray of NSArray as long as those NSArray’s members are Property Lists.
 Example 2: NSDictionary is one only if all keys and values are too

 Why define this term?
     Because the SDK has a number of methods which operate on Property Lists.
     Usually to read them from somewhere or write them out to somewhere.
     [plist writeToFile:(NSString *)path atomically:(BOOL)]; // plist is NSArray or
      NSDictionary
NSUserDefaults
 Lightweight storage of Property Lists.
 an NSDictionary that persists between launches of
  your application.
 Not a full-on database, so only store small things like
  user preferences.
Use NSError for Most Errors
 No network connectivity
 The remote web service may be inaccessible
 The remote web service may not be able to serve the
  information you request
 The data you receive may not match what you were
  expecting
Some Methods Pass Errors by
Reference
Exceptions Are Used for
Programmer Errors
Delegates and callbacks in
      Cocoa touch
SimpleTable App
How UITableDataSource work
SimpleTable App With Image
Simple Table App With Diff Image
SimpleTableView Custom Cell
Questions ?
Thank you.

More Related Content

What's hot

Lecture 2, c++(complete reference,herbet sheidt)chapter-12
Lecture 2, c++(complete reference,herbet sheidt)chapter-12Lecture 2, c++(complete reference,herbet sheidt)chapter-12
Lecture 2, c++(complete reference,herbet sheidt)chapter-12Abu Saleh
 
Objective-Cひとめぐり
Objective-CひとめぐりObjective-Cひとめぐり
Objective-CひとめぐりKenji Kinukawa
 
Memory Management C++ (Peeling operator new() and delete())
Memory Management C++ (Peeling operator new() and delete())Memory Management C++ (Peeling operator new() and delete())
Memory Management C++ (Peeling operator new() and delete())Sameer Rathoud
 
Declarative Name Binding and Scope Rules
Declarative Name Binding and Scope RulesDeclarative Name Binding and Scope Rules
Declarative Name Binding and Scope RulesEelco Visser
 
JavaScript introduction 1 ( Variables And Values )
JavaScript introduction 1 ( Variables And Values )JavaScript introduction 1 ( Variables And Values )
JavaScript introduction 1 ( Variables And Values )Victor Verhaagen
 
Core java by a introduction sandesh sharma
Core java by a introduction sandesh sharmaCore java by a introduction sandesh sharma
Core java by a introduction sandesh sharmaSandesh Sharma
 
Lecture 4.2 c++(comlete reference book)
Lecture 4.2 c++(comlete reference book)Lecture 4.2 c++(comlete reference book)
Lecture 4.2 c++(comlete reference book)Abu Saleh
 
Constructor and Destructor in c++
Constructor  and Destructor in c++Constructor  and Destructor in c++
Constructor and Destructor in c++aleenaguen
 
Objective-C Blocks and Grand Central Dispatch
Objective-C Blocks and Grand Central DispatchObjective-C Blocks and Grand Central Dispatch
Objective-C Blocks and Grand Central DispatchMatteo Battaglio
 
Advanced Java Practical File
Advanced Java Practical FileAdvanced Java Practical File
Advanced Java Practical FileSoumya Behera
 
Hey! There's OCaml in my Rust!
Hey! There's OCaml in my Rust!Hey! There's OCaml in my Rust!
Hey! There's OCaml in my Rust!Kel Cecil
 
Generics in .NET, C++ and Java
Generics in .NET, C++ and JavaGenerics in .NET, C++ and Java
Generics in .NET, C++ and JavaSasha Goldshtein
 
Java programming lab_manual_by_rohit_jaiswar
Java programming lab_manual_by_rohit_jaiswarJava programming lab_manual_by_rohit_jaiswar
Java programming lab_manual_by_rohit_jaiswarROHIT JAISWAR
 
Constructor in c++
Constructor in c++Constructor in c++
Constructor in c++Jay Patel
 

What's hot (20)

Memory management in c++
Memory management in c++Memory management in c++
Memory management in c++
 
Lecture 2, c++(complete reference,herbet sheidt)chapter-12
Lecture 2, c++(complete reference,herbet sheidt)chapter-12Lecture 2, c++(complete reference,herbet sheidt)chapter-12
Lecture 2, c++(complete reference,herbet sheidt)chapter-12
 
Objective-Cひとめぐり
Objective-CひとめぐりObjective-Cひとめぐり
Objective-Cひとめぐり
 
Memory Management C++ (Peeling operator new() and delete())
Memory Management C++ (Peeling operator new() and delete())Memory Management C++ (Peeling operator new() and delete())
Memory Management C++ (Peeling operator new() and delete())
 
Declarative Name Binding and Scope Rules
Declarative Name Binding and Scope RulesDeclarative Name Binding and Scope Rules
Declarative Name Binding and Scope Rules
 
JavaScript introduction 1 ( Variables And Values )
JavaScript introduction 1 ( Variables And Values )JavaScript introduction 1 ( Variables And Values )
JavaScript introduction 1 ( Variables And Values )
 
Constructors & destructors
Constructors & destructorsConstructors & destructors
Constructors & destructors
 
iOS Basic
iOS BasiciOS Basic
iOS Basic
 
Constructor
ConstructorConstructor
Constructor
 
Core java by a introduction sandesh sharma
Core java by a introduction sandesh sharmaCore java by a introduction sandesh sharma
Core java by a introduction sandesh sharma
 
Lecture 4.2 c++(comlete reference book)
Lecture 4.2 c++(comlete reference book)Lecture 4.2 c++(comlete reference book)
Lecture 4.2 c++(comlete reference book)
 
Constructor and Destructor in c++
Constructor  and Destructor in c++Constructor  and Destructor in c++
Constructor and Destructor in c++
 
Objective-C Blocks and Grand Central Dispatch
Objective-C Blocks and Grand Central DispatchObjective-C Blocks and Grand Central Dispatch
Objective-C Blocks and Grand Central Dispatch
 
Advanced Java Practical File
Advanced Java Practical FileAdvanced Java Practical File
Advanced Java Practical File
 
Hey! There's OCaml in my Rust!
Hey! There's OCaml in my Rust!Hey! There's OCaml in my Rust!
Hey! There's OCaml in my Rust!
 
Generics in .NET, C++ and Java
Generics in .NET, C++ and JavaGenerics in .NET, C++ and Java
Generics in .NET, C++ and Java
 
srgoc
srgocsrgoc
srgoc
 
Class method
Class methodClass method
Class method
 
Java programming lab_manual_by_rohit_jaiswar
Java programming lab_manual_by_rohit_jaiswarJava programming lab_manual_by_rohit_jaiswar
Java programming lab_manual_by_rohit_jaiswar
 
Constructor in c++
Constructor in c++Constructor in c++
Constructor in c++
 

Viewers also liked

Android session 2-behestee
Android session 2-behesteeAndroid session 2-behestee
Android session 2-behesteeHussain Behestee
 
Android session 3-behestee
Android session 3-behesteeAndroid session 3-behestee
Android session 3-behesteeHussain Behestee
 
Android session 4-behestee
Android session 4-behesteeAndroid session 4-behestee
Android session 4-behesteeHussain Behestee
 
iOS app dev Training - Session1
iOS app dev Training - Session1iOS app dev Training - Session1
iOS app dev Training - Session1Hussain Behestee
 
Echelon MillionAir magazine
Echelon MillionAir magazineEchelon MillionAir magazine
Echelon MillionAir magazineEchelonExp
 
CodeCamp general info
CodeCamp general infoCodeCamp general info
CodeCamp general infoTomi Juhola
 
ASP.NET MVC introduction
ASP.NET MVC introductionASP.NET MVC introduction
ASP.NET MVC introductionTomi Juhola
 
Ultimate Buenos Aires Tango Experience
Ultimate Buenos Aires Tango ExperienceUltimate Buenos Aires Tango Experience
Ultimate Buenos Aires Tango ExperienceEchelonExp
 
jQuery introduction
jQuery introductionjQuery introduction
jQuery introductionTomi Juhola
 

Viewers also liked (15)

Android session-5-sajib
Android session-5-sajibAndroid session-5-sajib
Android session-5-sajib
 
Android session 2-behestee
Android session 2-behesteeAndroid session 2-behestee
Android session 2-behestee
 
Android session 3-behestee
Android session 3-behesteeAndroid session 3-behestee
Android session 3-behestee
 
Android session 4-behestee
Android session 4-behesteeAndroid session 4-behestee
Android session 4-behestee
 
iOS app dev Training - Session1
iOS app dev Training - Session1iOS app dev Training - Session1
iOS app dev Training - Session1
 
Android session-1-sajib
Android session-1-sajibAndroid session-1-sajib
Android session-1-sajib
 
Echelon MillionAir magazine
Echelon MillionAir magazineEchelon MillionAir magazine
Echelon MillionAir magazine
 
CodeCamp general info
CodeCamp general infoCodeCamp general info
CodeCamp general info
 
ASP.NET MVC introduction
ASP.NET MVC introductionASP.NET MVC introduction
ASP.NET MVC introduction
 
iOS Training Session-3
iOS Training Session-3iOS Training Session-3
iOS Training Session-3
 
Ultimate Buenos Aires Tango Experience
Ultimate Buenos Aires Tango ExperienceUltimate Buenos Aires Tango Experience
Ultimate Buenos Aires Tango Experience
 
jQuery introduction
jQuery introductionjQuery introduction
jQuery introduction
 
บทนำ
บทนำบทนำ
บทนำ
 
Design Portfolio
Design PortfolioDesign Portfolio
Design Portfolio
 
manejo de cables
manejo de cablesmanejo de cables
manejo de cables
 

Similar to iOS Session-2

Similar to iOS Session-2 (20)

Objective c intro (1)
Objective c intro (1)Objective c intro (1)
Objective c intro (1)
 
Objective c
Objective cObjective c
Objective c
 
Runtime
RuntimeRuntime
Runtime
 
201005 accelerometer and core Location
201005 accelerometer and core Location201005 accelerometer and core Location
201005 accelerometer and core Location
 
Cocoa for Web Developers
Cocoa for Web DevelopersCocoa for Web Developers
Cocoa for Web Developers
 
Day 2
Day 2Day 2
Day 2
 
11. session 11 functions and objects
11. session 11   functions and objects11. session 11   functions and objects
11. session 11 functions and objects
 
constructors.pptx
constructors.pptxconstructors.pptx
constructors.pptx
 
Pavel kravchenko obj c runtime
Pavel kravchenko obj c runtimePavel kravchenko obj c runtime
Pavel kravchenko obj c runtime
 
Objective c slide I
Objective c slide IObjective c slide I
Objective c slide I
 
Object Trampoline: Why having not the object you want is what you need.
Object Trampoline: Why having not the object you want is what you need.Object Trampoline: Why having not the object you want is what you need.
Object Trampoline: Why having not the object you want is what you need.
 
Sonu wiziq
Sonu wiziqSonu wiziq
Sonu wiziq
 
01 objective-c session 1
01  objective-c session 101  objective-c session 1
01 objective-c session 1
 
JavaScript(Es5) Interview Questions & Answers
JavaScript(Es5)  Interview Questions & AnswersJavaScript(Es5)  Interview Questions & Answers
JavaScript(Es5) Interview Questions & Answers
 
Chap-2 Classes & Methods.pptx
Chap-2 Classes & Methods.pptxChap-2 Classes & Methods.pptx
Chap-2 Classes & Methods.pptx
 
Ios development
Ios developmentIos development
Ios development
 
Advance Java
Advance JavaAdvance Java
Advance Java
 
Understanding linq
Understanding linqUnderstanding linq
Understanding linq
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rd
 
Getting Input from User
Getting Input from UserGetting Input from User
Getting Input from User
 

Recently uploaded

Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 

Recently uploaded (20)

Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 

iOS Session-2

  • 1. Session - 2 Presented By: A.T.M. Hassan Uzzaman
  • 2. Agendas  OOP Concepts in Objective-c  Delegates and callbacks in Cocoa touch  Table View, Customizing Cells  PList (Read, write)
  • 3. Obj-C vs C# Obj-C C# [[object method] method]; obj.method().method(); Memory Pools Garbage Collection +/- static/instance nil null (void)methodWithArg:(int)value {} void method(int value) {} YES NO true false @protocol interface
  • 4. Classes from Apple (and some history)  NSString is a string of text that is immutable.  NSMutableString is a string of text that is mutable.  NSArray is an array of objects that is immutable.  NSMutableArray is an array of objects that is mutable.  NSNumber holds a numeric value.
  • 5. Objective-C Characteristics and Symbols  Written differently from other languages  Object communicate with messages—does not “call” a method.  @ indicates a compiler directive. Objective-C has own preprocessor that processes @ directives.  # indicates a preprocessor directive. Processes any # before it compiles.
  • 6. Declare in Header file (.h) Each method will start with either a – or a + symbol. - indicates an instance method (the receiver is an instance) +indicates a class method (the receiver is a class name) Example of a instance method -(IBAction)buttonPressed:(id)sender; Or with one argument -(void)setFillColor:(NSColor*) newFillColor;
  • 7. Parts of a Method in a Class  Implement the method in the .m file  Example: -(IBAction)buttonPressed:(id)sender{ do code here…. }  Example 2: -(void) setOutlineColor:(NSColor*) outlineColor{ do code here…. }
  • 8. Class Declaration (Interface) Node.h #import <Cocoa/Cocoa.h> @interface Node : NSObject { Node *link; int contents; Class is Node who’s parent is } NSObject +(id)new; { class variables } -(void)setContent:(int)number; -(void)setLink:(Node*)next; -(int)getContent; +/- private/public methods of Class -(Node*)getLink; @end Class variables are private
  • 9. Class Definition (Implementation) #import “Node.h” @implementation Node Node.m +(id)new { return [Node alloc];} -(void)setContent:(int)number {contents = number;} -(void)setLink:(Node*)next { [link autorelease]; link = [next retain]; Like your C++ .cpp } file -(int)getContent {return contents;} -(Node*)getLink >>just give the {return link;} methods here @end
  • 10. Creating class instances Creating an Object ClassName *object = [[ClassName alloc] init]; ClassName *object = [[ClassName alloc] initWith* ];  NSString* myString = [[NSString alloc] init];  Nested method call. The first is the alloc method called on NSString itself. This is a relatively low-level call which reserves memory and instantiates an object. The second is a call to init on the new object. The init implementation usually does basic setup, such as creating instance variables. The details of that are unknown to you as a client of the class. In some cases, you may use a different version of init which takes input: ClassName *object = [ClassName method_to_create];  NSString* myString = [NSString string];  Some classes may define a special method that will in essence call alloc followed by some kind of init
  • 11. Reference [[Person alloc] init];action Person *person = counting in Retain count begins at 1 with +alloc [person retain]; Retain count increases to 2 with -retain [person release]; Retain count decreases to 1 with -release [person release]; Retain count decreases to 0, -dealloc automatically called
  • 12. Autorelease  Example: returning a newly created object -(NSString *)fullName { NSString *result; result = [[NSString alloc] initWithFormat:@“%@ %@”, firstName, lastName]; [result autorelease] return result; }
  • 13. Method Names & Autorelease  Methods whose names includes alloc, copy, or new return a retained object that the caller needs to release NSMutableString *string = [[NSMutableString alloc] init]; // We are responsible for calling -release or -autorelease [string autorelease];  All other methods return autoreleased objects NSMutableString *string = [NSMutableString string]; // The method name doesn’t indicate that we need to release it, so don’t  This is a convention- follow it in methods you define!
  • 14. Polymorphism  Just as the fields of a C structure are in a protected namespace, so are an object’s instance variables.  Method names are also protected. Unlike the names of C functions, method names aren’t global symbols. The name of a method in one class can’t conflict with method names in other classes; two very different classes can implement identically named methods.  Objective-C implements polymorphism of method names, but not parameter or operator overloading.
  • 15. Inheritance  Class Hierarchies  Subclass Definitions  Uses of Inheritance
  • 21. NSDictionary  Immutable hash table. Look up objects using a key to get a value. + (id)dictionaryWithObjects:(NSArray *)values forKeys:(NSArray *)keys; + (id)dictionaryWithObjectsAndKeys:(id)firstObject, ...;  Creation example: NSDictionary *base = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:2], @“binary”, [NSNumber numberWithInt:16], @“hexadecimal”, nil];  Methods  - (int)count;  - (id)objectForKey:(id)key;  - (NSArray *)allKeys;  - (NSArray *)allValues; see documentation (apple.com) for more details
  • 22. NSMutableDictionary  Changeable + (id)dictionaryWithObjects:(NSArray *)values forKeys:(NSArray *)keys; + (id)dictionaryWithObjectsAndKeys:(id)firstObject, ...;  Creation : + (id)dictionary; //creates empty dictionary  Methods - (void)setObject:(id)anObject forKey:(id)key; - (void)removeObjectForKey:(id)key; - (void)removeAllObjects; - (void)addEntriesFromDictionary:(NSDictionary *)otherDictionary; see documentation (apple.com) for more details
  • 23. We will see this in Property list (plist) practice later  A collection of collections  Specifically, it is any graph of objects containing only the following classes:  NSArray, NSDictionary, NSNumber, NSString, NSDate, NSData  Example1 : NSArray is a Property List if all its members are too  NSArray of NSString is a Property List  NSArray of NSArray as long as those NSArray’s members are Property Lists.  Example 2: NSDictionary is one only if all keys and values are too  Why define this term?  Because the SDK has a number of methods which operate on Property Lists.  Usually to read them from somewhere or write them out to somewhere.  [plist writeToFile:(NSString *)path atomically:(BOOL)]; // plist is NSArray or NSDictionary
  • 24. NSUserDefaults  Lightweight storage of Property Lists.  an NSDictionary that persists between launches of your application.  Not a full-on database, so only store small things like user preferences.
  • 25. Use NSError for Most Errors  No network connectivity  The remote web service may be inaccessible  The remote web service may not be able to serve the information you request  The data you receive may not match what you were expecting
  • 26. Some Methods Pass Errors by Reference
  • 27. Exceptions Are Used for Programmer Errors
  • 28. Delegates and callbacks in Cocoa touch
  • 32. Simple Table App With Diff Image