SlideShare ist ein Scribd-Unternehmen logo
1 von 15
Downloaden Sie, um offline zu lesen
Objective-C
Classes, Protocols, Delegates
      for iOS Beginners




                    Adam Musial-Bright, @a_life_hacker
Classes & Objects


Objective-C is an object oriented language -
this is good, because you can model things.
Modeling the world
Like an architect creates a plan for a house ...




                     http://www.freedigitalphotos.net



... you create a plan for your software.
So plan with classes
A class for ...
                      Roof
                                                   Window
             Wall


                                                  Door
             House     http://www.freedigitalphotos.net


                     Basement
Now translated to iOS
 Window        Door            Basement

          ... could be a ...


 NSView     NSButton           NSString
Class example
The interface and the implementation come always as a pair.
  #import <Foundation/Foundation.h>          #import "Window.h"

  @interface Window : NSObject               @interface Window()
                                             @property NSString *state;
  - (void)open;                              @end

  - (void)close;                             @implementation Window

  - (BOOL)isOpen;                            @synthesize state = _state;

  - (UIImage *)image;                        - (id)init {
                                                 if (self = [super init]) {
  @end                                               self.state = @"closed";
                                                     return self;
                                                 } else {
                                                     return nil;
                                                 }
                                             }

                                                     - (void)open {
                                                         self.state = @"open";
                                                     }
                    http://www.freedigitalphotos.net ...
Classes and Objects
#import <Foundation/Foundation.h>                    #import "Window.h"

@interface Window : NSObject                         @interface Window()
                                                     @property NSString *state;
- (void)open;                                        @end

- (void)close;                                       @implementation Window

- (BOOL)isOpen;                                      @synthesize state = _state;

- (UIImage *)image;                 - (id)init {
                                        if (self = [super init]) {
@end                                        self.state = @"closed";
                                                       two independent
                                            return self;
       Window *northWindow = [[Window alloc] init];
                                        } else {
                                                                                            objects
       Window *southWindow = [[Window alloc] init];
                                            return nil;
                                        }
       [northWindow open];      open the north window
                                    }
       [northWindow isOpen]; // -> open
                                    - (void)open {
       [southWindow isOpen]; // -> closed     the south window
                                        self.state = @"open";
                                                                                    stays closed
                                    }

                                                     ...
                                                                 The interface and the
                  http://www.freedigitalphotos.net         implementation come always as pair.
Class syntax & semantics
#import “MyImportedLibraryHeader.h”           #import "MyClassName.h"

@interface MyClassName : SuperClass           @interface MyClassName()
                                              // private interface
+ (void)classMethod;                          @end

- (void)instenceMethod;                       @implementation MyClassName

- (NSString *)methodWithReturnValue;          - (id)init {
                                                  if (self = [super init]) {
- (void)methodWithParameter:(NSString *)text;         // do some stuff here
                                                      return self;
@end                                              } else {
                                                      return nil;
                                                  }
                                              }

                                              - (void)instanceMethod {
                                                  NSLog(@”log output”);
                                              }

                                              ...

                                              @end
Class take-away #1
#import <Foundation/Foundation.h>   #import "Window.h"     private interface are only
                                                         visible in the implementation
@interface Window : NSObject        @interface Window()
                                    @property NSString *state;
- (void)open;                       @end

- (void)close;                      @implementation Window      synthesize properties
- (BOOL)isOpen;                     @synthesize state = _state;

- (UIImage *)image;                 - (id)init {
                                        if (self = [super init]) {
@end                                        self.state = @"closed";
the interface defines public                 return self;
  methods like “open”, or               } else {          prepare the object state
                                            return nil;
   “close” the window                   }
                                                               when initialized
                                    }

                                    - (void)open {
                                        self.state = @"open";
                                    }
                                            access properties easily
                                    ...
                                              with the “.” notation
Class take-away #2




     connect view elements
    with controller objects to
             outlets
Delegate & Protocol
                           Do not call me all the time...
                                            ...I call you back
                                           when I am ready!

                                   There are moments
                                   where we want an
                                    objects to send a
                                    message to us - a
http://www.freedigitalphotos.net
                                        callback.         http://www.freedigitalphotos.net
Define a protocol
                                    the protocol defines the
#import <Foundation/Foundation.h>
                                        callback method
@protocol NoiseDelegate <NSObject>       “makeNoise”
@required
- (void)makesNoise:(NSString *)noise;
@end
                                             @implementation Window
@interface Window : NSObject {
                                             @synthesize delegate = _delegate;
    id <NoiseDelegate> delegate;
}
                          here we have a     ...            synthesize and execute your
@property id delegate;    delegate and a                       “makeNoise” callback
                                             - (void)close {
                                                 self.state = @"closed";
- (void)open;            delegate property       int r = arc4random() % 4;
                                                 if (r == 0) {
- (void)close;
                                                     [self.delegate makesNoise:@"bang!"];
                                                 } else {
- (BOOL)isOpen;
                                                     [self.delegate makesNoise:@""];
                                                 }
- (UIImage *)image;
                                             }
@end
                                             ...         25% of closed windows
                                                          make a “bang!” noise
Use the delegate
       ... and make some noise when the window is closed.
#import <UIKit/UIKit.h>
#import "Window.h"

@interface HouseViewController :             @implementation HouseViewController
UIViewController <NoiseDelegate> {
                                             ...
   IBOutlet   UIButton *northWindowButton;
   IBOutlet   UIButton *southWindowButton;   [self.northWindow setDelegate:self];
   IBOutlet   UIImageView *northImageView;   [self.southWindow setDelegate:self];
   IBOutlet   UIImageView *southImageView;

}
   IBOutlet   UILabel *noiseLabel;                    set the house controller as a
@end                                                        window delegate
       use the delegate in the class         ...

       interface where the callback
            should be executed
                                             - (void)makesNoise:(NSString *)noise {
                                                 noiseLabel.text = noise;
                                             }
                                                    implement the callback required
                                             ...
                                                           by the delegate
Protocol take-away
               ... send a asynchronous HTTP request ...
@implementation WebService : NSObject

- (void)sendRequest {
     NSURL *url = [NSURL URLWithString:@"http://www.google.com"];

      NSURLRequest *urlRequest = [NSURLRequest
         requestWithURL:url
         cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
         timeoutInterval:30];

       NSURLConnection *connection = [[NSURLConnection alloc]
          initWithRequest:urlRequest delegate:controller];
      ...
}                                                       set a delegate to receive a
- (void)connection:(NSURLConnection *)connection
                                                      response, connection error or
    didReceiveResponse:(NSURLResponse *)response {               timeouts
    ...
}

...
Presentation
  http://www.slideshare.net/musial-bright




  Code
  https://github.com/musial-bright/iOSBeginners




Thank you + Q&A
                           Adam Musial-Bright, @a_life_hacker

Weitere ähnliche Inhalte

Was ist angesagt?

Advanced JavaScript Concepts
Advanced JavaScript ConceptsAdvanced JavaScript Concepts
Advanced JavaScript ConceptsNaresh Kumar
 
Apache Commons - Don\'t re-invent the wheel
Apache Commons - Don\'t re-invent the wheelApache Commons - Don\'t re-invent the wheel
Apache Commons - Don\'t re-invent the wheeltcurdt
 
Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Juan Pablo
 
Java ppt Gandhi Ravi (gandhiri@gmail.com)
Java ppt  Gandhi Ravi  (gandhiri@gmail.com)Java ppt  Gandhi Ravi  (gandhiri@gmail.com)
Java ppt Gandhi Ravi (gandhiri@gmail.com)Gandhi Ravi
 
Kotlin delegates in practice - Kotlin Everywhere Stockholm
Kotlin delegates in practice - Kotlin Everywhere StockholmKotlin delegates in practice - Kotlin Everywhere Stockholm
Kotlin delegates in practice - Kotlin Everywhere StockholmFabio Collini
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced JavascriptAdieu
 
Kotlin Delegates in practice - Kotlin community conf
Kotlin Delegates in practice - Kotlin community confKotlin Delegates in practice - Kotlin community conf
Kotlin Delegates in practice - Kotlin community confFabio Collini
 
C# Delegates, Events, Lambda
C# Delegates, Events, LambdaC# Delegates, Events, Lambda
C# Delegates, Events, LambdaJussi Pohjolainen
 
Week 06 Modular Javascript_Brandon, S. H. Wu
Week 06 Modular Javascript_Brandon, S. H. WuWeek 06 Modular Javascript_Brandon, S. H. Wu
Week 06 Modular Javascript_Brandon, S. H. WuAppUniverz Org
 
My Favourite 10 Things about Xcode/ObjectiveC
My Favourite 10 Things about Xcode/ObjectiveCMy Favourite 10 Things about Xcode/ObjectiveC
My Favourite 10 Things about Xcode/ObjectiveCJohnKennedy
 
Understanding JavaScript
Understanding JavaScriptUnderstanding JavaScript
Understanding JavaScriptnodejsbcn
 
Exercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera CymbronExercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera Cymbroncymbron
 
Unbundling the JavaScript module bundler - DevIT
Unbundling the JavaScript module bundler - DevITUnbundling the JavaScript module bundler - DevIT
Unbundling the JavaScript module bundler - DevITLuciano Mammino
 

Was ist angesagt? (20)

Advanced JavaScript Concepts
Advanced JavaScript ConceptsAdvanced JavaScript Concepts
Advanced JavaScript Concepts
 
Oojs 1.1
Oojs 1.1Oojs 1.1
Oojs 1.1
 
Day 1
Day 1Day 1
Day 1
 
Apache Commons - Don\'t re-invent the wheel
Apache Commons - Don\'t re-invent the wheelApache Commons - Don\'t re-invent the wheel
Apache Commons - Don\'t re-invent the wheel
 
Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#
 
Java ppt Gandhi Ravi (gandhiri@gmail.com)
Java ppt  Gandhi Ravi  (gandhiri@gmail.com)Java ppt  Gandhi Ravi  (gandhiri@gmail.com)
Java ppt Gandhi Ravi (gandhiri@gmail.com)
 
Constructors & destructors
Constructors & destructorsConstructors & destructors
Constructors & destructors
 
Testable Javascript
Testable JavascriptTestable Javascript
Testable Javascript
 
iOS Session-2
iOS Session-2iOS Session-2
iOS Session-2
 
Kotlin delegates in practice - Kotlin Everywhere Stockholm
Kotlin delegates in practice - Kotlin Everywhere StockholmKotlin delegates in practice - Kotlin Everywhere Stockholm
Kotlin delegates in practice - Kotlin Everywhere Stockholm
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
 
Kotlin Delegates in practice - Kotlin community conf
Kotlin Delegates in practice - Kotlin community confKotlin Delegates in practice - Kotlin community conf
Kotlin Delegates in practice - Kotlin community conf
 
Anonymous functions in JavaScript
Anonymous functions in JavaScriptAnonymous functions in JavaScript
Anonymous functions in JavaScript
 
C# Delegates, Events, Lambda
C# Delegates, Events, LambdaC# Delegates, Events, Lambda
C# Delegates, Events, Lambda
 
Week 06 Modular Javascript_Brandon, S. H. Wu
Week 06 Modular Javascript_Brandon, S. H. WuWeek 06 Modular Javascript_Brandon, S. H. Wu
Week 06 Modular Javascript_Brandon, S. H. Wu
 
My Favourite 10 Things about Xcode/ObjectiveC
My Favourite 10 Things about Xcode/ObjectiveCMy Favourite 10 Things about Xcode/ObjectiveC
My Favourite 10 Things about Xcode/ObjectiveC
 
Understanding JavaScript
Understanding JavaScriptUnderstanding JavaScript
Understanding JavaScript
 
Exercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera CymbronExercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera Cymbron
 
Operator overload rr
Operator overload  rrOperator overload  rr
Operator overload rr
 
Unbundling the JavaScript module bundler - DevIT
Unbundling the JavaScript module bundler - DevITUnbundling the JavaScript module bundler - DevIT
Unbundling the JavaScript module bundler - DevIT
 

Ähnlich wie Objective-C for Beginners

Java Concurrency Gotchas
Java Concurrency GotchasJava Concurrency Gotchas
Java Concurrency GotchasAlex Miller
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScriptDonald Sipe
 
Javaoneconcurrencygotchas 090610192215 Phpapp02
Javaoneconcurrencygotchas 090610192215 Phpapp02Javaoneconcurrencygotchas 090610192215 Phpapp02
Javaoneconcurrencygotchas 090610192215 Phpapp02Tarun Kumar
 
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」matuura_core
 
Agile Iphone Development
Agile Iphone DevelopmentAgile Iphone Development
Agile Iphone DevelopmentGiordano Scalzo
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScriptNascenia IT
 
Ian 20150116 java script oop
Ian 20150116 java script oopIan 20150116 java script oop
Ian 20150116 java script oopLearningTech
 
Beginning icloud development - Cesare Rocchi - WhyMCA
Beginning icloud development - Cesare Rocchi - WhyMCABeginning icloud development - Cesare Rocchi - WhyMCA
Beginning icloud development - Cesare Rocchi - WhyMCAWhymca
 
Designing for Windows Phone 8
Designing for Windows Phone 8Designing for Windows Phone 8
Designing for Windows Phone 8David Isbitski
 
Lecture 6, c++(complete reference,herbet sheidt)chapter-16
Lecture 6, c++(complete reference,herbet sheidt)chapter-16Lecture 6, c++(complete reference,herbet sheidt)chapter-16
Lecture 6, c++(complete reference,herbet sheidt)chapter-16Abu Saleh
 
Javascript basic course
Javascript basic courseJavascript basic course
Javascript basic courseTran Khoa
 
Lombok Features
Lombok FeaturesLombok Features
Lombok Features文峰 眭
 
05 JavaScript #burningkeyboards
05 JavaScript #burningkeyboards05 JavaScript #burningkeyboards
05 JavaScript #burningkeyboardsDenis Ristic
 
JavaScript Closures for Dummies & JavaScript prototype, closures and OOP.
JavaScript Closures for Dummies & JavaScript prototype, closures and OOP.JavaScript Closures for Dummies & JavaScript prototype, closures and OOP.
JavaScript Closures for Dummies & JavaScript prototype, closures and OOP.Jin-Hwa Kim
 

Ähnlich wie Objective-C for Beginners (20)

Iphone course 1
Iphone course 1Iphone course 1
Iphone course 1
 
Java Concurrency Gotchas
Java Concurrency GotchasJava Concurrency Gotchas
Java Concurrency Gotchas
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
 
Javascript tid-bits
Javascript tid-bitsJavascript tid-bits
Javascript tid-bits
 
Javaoneconcurrencygotchas 090610192215 Phpapp02
Javaoneconcurrencygotchas 090610192215 Phpapp02Javaoneconcurrencygotchas 090610192215 Phpapp02
Javaoneconcurrencygotchas 090610192215 Phpapp02
 
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
 
Agile Iphone Development
Agile Iphone DevelopmentAgile Iphone Development
Agile Iphone Development
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
 
Ian 20150116 java script oop
Ian 20150116 java script oopIan 20150116 java script oop
Ian 20150116 java script oop
 
Say It With Javascript
Say It With JavascriptSay It With Javascript
Say It With Javascript
 
Beginning icloud development - Cesare Rocchi - WhyMCA
Beginning icloud development - Cesare Rocchi - WhyMCABeginning icloud development - Cesare Rocchi - WhyMCA
Beginning icloud development - Cesare Rocchi - WhyMCA
 
Javascript
JavascriptJavascript
Javascript
 
Designing for Windows Phone 8
Designing for Windows Phone 8Designing for Windows Phone 8
Designing for Windows Phone 8
 
Lecture 6, c++(complete reference,herbet sheidt)chapter-16
Lecture 6, c++(complete reference,herbet sheidt)chapter-16Lecture 6, c++(complete reference,herbet sheidt)chapter-16
Lecture 6, c++(complete reference,herbet sheidt)chapter-16
 
Javascript basic course
Javascript basic courseJavascript basic course
Javascript basic course
 
6976.ppt
6976.ppt6976.ppt
6976.ppt
 
Lombok Features
Lombok FeaturesLombok Features
Lombok Features
 
05 JavaScript #burningkeyboards
05 JavaScript #burningkeyboards05 JavaScript #burningkeyboards
05 JavaScript #burningkeyboards
 
JavaScript Closures for Dummies & JavaScript prototype, closures and OOP.
JavaScript Closures for Dummies & JavaScript prototype, closures and OOP.JavaScript Closures for Dummies & JavaScript prototype, closures and OOP.
JavaScript Closures for Dummies & JavaScript prototype, closures and OOP.
 
Titanium mobile
Titanium mobileTitanium mobile
Titanium mobile
 

Kürzlich hochgeladen

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 

Kürzlich hochgeladen (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 

Objective-C for Beginners

  • 1. Objective-C Classes, Protocols, Delegates for iOS Beginners Adam Musial-Bright, @a_life_hacker
  • 2. Classes & Objects Objective-C is an object oriented language - this is good, because you can model things.
  • 3. Modeling the world Like an architect creates a plan for a house ... http://www.freedigitalphotos.net ... you create a plan for your software.
  • 4. So plan with classes A class for ... Roof Window Wall Door House http://www.freedigitalphotos.net Basement
  • 5. Now translated to iOS Window Door Basement ... could be a ... NSView NSButton NSString
  • 6. Class example The interface and the implementation come always as a pair. #import <Foundation/Foundation.h> #import "Window.h" @interface Window : NSObject @interface Window() @property NSString *state; - (void)open; @end - (void)close; @implementation Window - (BOOL)isOpen; @synthesize state = _state; - (UIImage *)image; - (id)init { if (self = [super init]) { @end self.state = @"closed"; return self; } else { return nil; } } - (void)open { self.state = @"open"; } http://www.freedigitalphotos.net ...
  • 7. Classes and Objects #import <Foundation/Foundation.h> #import "Window.h" @interface Window : NSObject @interface Window() @property NSString *state; - (void)open; @end - (void)close; @implementation Window - (BOOL)isOpen; @synthesize state = _state; - (UIImage *)image; - (id)init { if (self = [super init]) { @end self.state = @"closed"; two independent return self; Window *northWindow = [[Window alloc] init]; } else { objects Window *southWindow = [[Window alloc] init]; return nil; } [northWindow open]; open the north window } [northWindow isOpen]; // -> open - (void)open { [southWindow isOpen]; // -> closed the south window self.state = @"open"; stays closed } ... The interface and the http://www.freedigitalphotos.net implementation come always as pair.
  • 8. Class syntax & semantics #import “MyImportedLibraryHeader.h” #import "MyClassName.h" @interface MyClassName : SuperClass @interface MyClassName() // private interface + (void)classMethod; @end - (void)instenceMethod; @implementation MyClassName - (NSString *)methodWithReturnValue; - (id)init { if (self = [super init]) { - (void)methodWithParameter:(NSString *)text; // do some stuff here return self; @end } else { return nil; } } - (void)instanceMethod { NSLog(@”log output”); } ... @end
  • 9. Class take-away #1 #import <Foundation/Foundation.h> #import "Window.h" private interface are only visible in the implementation @interface Window : NSObject @interface Window() @property NSString *state; - (void)open; @end - (void)close; @implementation Window synthesize properties - (BOOL)isOpen; @synthesize state = _state; - (UIImage *)image; - (id)init { if (self = [super init]) { @end self.state = @"closed"; the interface defines public return self; methods like “open”, or } else { prepare the object state return nil; “close” the window } when initialized } - (void)open { self.state = @"open"; } access properties easily ... with the “.” notation
  • 10. Class take-away #2 connect view elements with controller objects to outlets
  • 11. Delegate & Protocol Do not call me all the time... ...I call you back when I am ready! There are moments where we want an objects to send a message to us - a http://www.freedigitalphotos.net callback. http://www.freedigitalphotos.net
  • 12. Define a protocol the protocol defines the #import <Foundation/Foundation.h> callback method @protocol NoiseDelegate <NSObject> “makeNoise” @required - (void)makesNoise:(NSString *)noise; @end @implementation Window @interface Window : NSObject { @synthesize delegate = _delegate; id <NoiseDelegate> delegate; } here we have a ... synthesize and execute your @property id delegate; delegate and a “makeNoise” callback - (void)close { self.state = @"closed"; - (void)open; delegate property int r = arc4random() % 4; if (r == 0) { - (void)close; [self.delegate makesNoise:@"bang!"]; } else { - (BOOL)isOpen; [self.delegate makesNoise:@""]; } - (UIImage *)image; } @end ... 25% of closed windows make a “bang!” noise
  • 13. Use the delegate ... and make some noise when the window is closed. #import <UIKit/UIKit.h> #import "Window.h" @interface HouseViewController : @implementation HouseViewController UIViewController <NoiseDelegate> { ... IBOutlet UIButton *northWindowButton; IBOutlet UIButton *southWindowButton; [self.northWindow setDelegate:self]; IBOutlet UIImageView *northImageView; [self.southWindow setDelegate:self]; IBOutlet UIImageView *southImageView; } IBOutlet UILabel *noiseLabel; set the house controller as a @end window delegate use the delegate in the class ... interface where the callback should be executed - (void)makesNoise:(NSString *)noise { noiseLabel.text = noise; } implement the callback required ... by the delegate
  • 14. Protocol take-away ... send a asynchronous HTTP request ... @implementation WebService : NSObject - (void)sendRequest { NSURL *url = [NSURL URLWithString:@"http://www.google.com"]; NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:30]; NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:controller]; ... } set a delegate to receive a - (void)connection:(NSURLConnection *)connection response, connection error or didReceiveResponse:(NSURLResponse *)response { timeouts ... } ...
  • 15. Presentation http://www.slideshare.net/musial-bright Code https://github.com/musial-bright/iOSBeginners Thank you + Q&A Adam Musial-Bright, @a_life_hacker