SlideShare uma empresa Scribd logo
1 de 42
How to develop an iOS application
          Objective C – Xcode – iOS




                                      Le Thanh Quang
                                        Mobile team
                                         April 19th 2012
Agenda


              Objective-C in brief



                           Xcode



                 iOS frameworks




         www.exoplatform.com - Copyright 2012 eXo Platform   2
Objective-C




www.exoplatform.com - Copyright 2012 eXo Platform   3
Objective-C – What is it?

Simple extension of the C language


Adds object-oriented capabilities to C language
      Runtime system (C library)
      Dynamic typing
      Dynamic binding


GCC/Clang compiler supports both C and Objective-C
      Apple donated Objective-C for GNU project (open source)




                  www.exoplatform.com - Copyright 2012 eXo Platform   4
Objective-C – Who use?

Apple Inc.


Mac OS X developers
      Cocoa framework
      Core animation, Core data, etc
iOS developers
      Cocoa touch framework
      Core animation, Core data, etc




                  www.exoplatform.com - Copyright 2012 eXo Platform   5
Objective-C – Why should I (Java developer) care?

Make up your mind with new code designs


iPhone/iPad devices become popular rich user agents in
  enterprise market


eXo Platform 3.5, cloud-workspaces.com are integrated with iOS
  based devices and Android family


Play around for fun or profit in free time ;)




                   www.exoplatform.com - Copyright 2012 eXo Platform   6
Objective-C – History


          Appeared in                                           1983


          Designed by                               Tom Love & Brad Fox


      Major implementations                                GCC, Clang


          Influenced by                                    Smalltalk, C


              OS                                         Cross-platform




                 www.exoplatform.com - Copyright 2012 eXo Platform        7
Objective-C and Java

   Java
              Almost everywhere
              … except iPhone




                             Objective-C
   Platform
                                                  Mac OS X
                                                  iPhone, iPad, ...




                 www.exoplatform.com - Copyright 2012 eXo Platform    8
Objective-C and Java                                            Message Syntax


Java

                       myString.toString()




Objective-C
              * Square brackets for message expressions

                        [myString description]




                   www.exoplatform.com - Copyright 2012 eXo Platform             9
Objective-C and Java                                        Method arguments

Java

               person.setFirstName(“Fred”)




Objective-C
          * Arguments are delimited by colons

                  [person setFirstName:@”Fred”]




                 www.exoplatform.com - Copyright 2012 eXo Platform             10
Objective-C and Java                                 Object Data types

Java
                 Employee emp = new Employee();



Objective-C

       * Objective-C objects are dynamically allocated structs
           Employee *emp = [[Employee alloc] init];


       * Providing generic object type, id
            id emp2 = [[Employee alloc] init];




                     www.exoplatform.com - Copyright 2012 eXo Platform   11
Objective-C and Java                                    Object Data types

Java
                    * Constructors
                    Employee emp = new Employee();


Objective-C

             Employee *emp = [[Employee alloc] init];

       *   Creation methods are just methods
       *   Calls to super can occur anywhere within a method
       *   Inheritance is straight-forward
       *   Memory allocations and initialization are separate steps




                        www.exoplatform.com - Copyright 2012 eXo Platform   12
Objective-C and Java                           Prefix vs Package path

Java
         java.lang.String s = new String(“hello”);



Objective-C

    * Objective-C doesn't provide namespaces
    * Frameworks and libraries use prefixes by convention to avoid collision

    NSString *s = [NSString alloc] initWithString:@”Hi”];

   ==> NS is prefix for classes of Foundation Framework.




                     www.exoplatform.com - Copyright 2012 eXo Platform         13
Objective-C and Java                             Method prototypes

Java               public void sayHello() {
                      …
                   }


Objective-C

              * Methods declared in .h file, implemented in .m
              * Instance methods prefixed with -
              * Class methods prefixed with +
         Ex:
          // Method declarations
              - (id)init;
              - (id)alloc;




                   www.exoplatform.com - Copyright 2012 eXo Platform   14
Objective-C and Java                              Method prototypes

Objective-C

 * No method overloading
     * Runtime system looks up methods by name rather than signatures

 * Method names can be composed of multiple sections

   Ex:
     - (void)addEmployee:(Employee *)emp withTitle:
 (NSString *)title

     Name of method is addEmployee:withTitle




                    www.exoplatform.com - Copyright 2012 eXo Platform   15
Objective-C and Java                                    Class

Java
                                  ...



Objective-C




              www.exoplatform.com - Copyright 2012 eXo Platform   16
Objective-C and Java              Anatomy of Class Declaration




              www.exoplatform.com - Copyright 2012 eXo Platform   17
Objective-C                              Class Implementation




              www.exoplatform.com - Copyright 2012 eXo Platform   18
Objective-C and Java                                    Class

Java
                                  ...



Objective-C




              www.exoplatform.com - Copyright 2012 eXo Platform   19
Objective-C – Memory management

* Reference counting
       –    (id)retain; // increase retain count
       –    (id)release; // decrease retain count
       –    (id)autorelease; // release with a delay
       –    (void)dealloc; // call by release when retain
            count = 1
* Creation methods set retain count to 1
       –    Creation methods whose names start with alloc or new or
            contain copy
       –    Those who call creation methods MUST call either release or
            autorelease also
       –    Never call dealloc directly



                   www.exoplatform.com - Copyright 2012 eXo Platform      20
Objective-C – Memory management




             www.exoplatform.com - Copyright 2012 eXo Platform   21
Objective-C – Categories




              www.exoplatform.com - Copyright 2012 eXo Platform   22
Objective-C – Using category




              www.exoplatform.com - Copyright 2012 eXo Platform   23
Objective-C – Blocks

A block of code
          –     A sequence of statements inside {}
          –     Start with the magical character caret ^

Ex:
[aDictionary enumerateKeysAndObjectsUsingBlock:^(id key,
  id value, BOOL *stop) {
      NSLog(@“value for key %@ is %@”, key, value);
      if ([@“ENOUGH” isEqualToString:key]) {
              *stop = YES;
      }
}];



                       www.exoplatform.com - Copyright 2012 eXo Platform   24
Objective-C – Blocks
A block of code
          –     Can use local variables declared before the block inside the
                block
          –     But they are read only!

Ex:
double stopValue = 53.5;
[aDictionary enumerateKeysAndObjectsUsingBlock:^(id key,
  id value, BOOL *stop) {
      NSLog(@“value for key %@ is %@”, key, value);
     if ([@“ENOUGH” isEqualToString:key] || ([value
  doubleValue] == stopValue)) {
              *stop = YES;
          stoppedEarly = YES; // ILLEGAL
      }
}];
                       www.exoplatform.com - Copyright 2012 eXo Platform       25
Objective-C – Blocks
When do we use blocks in iOS?
      –   Enumeration
      –   View Animations
      –   Sorting (sort this thing using a block as the comparison method)
      –   Notification (when something happens, execute this block)
      –   Error handlers (if an error happens while doing this, execute this
          block)
      –   Completion handlers (when you are done doing this, execute this
          block)


And a super-important use: Multithreading




                 www.exoplatform.com - Copyright 2012 eXo Platform             26
Xcode




www.exoplatform.com - Copyright 2012 eXo Platform   27
Xcode
IDE for iPhone projects
        –   Build
        –   Run (Simulator, device)
        –   Debug
        –   Source code management (SCM)
        –   Documentation




                    www.exoplatform.com - Copyright 2012 eXo Platform   28
Xcode
Automatically maintain build scripts


Display logical grouping of files
        No package paths
        By default, groups not mapped to folder structure
Resources
        Automatically bundled with executable
Frameworks
        Linked at compile time; no classpath needed




                     www.exoplatform.com - Copyright 2012 eXo Platform   29
Xcode - Interface Builder


Visual GUI design tool


Doesn't generate code


Working with “freeze-dried” objects
       –    Archived (serialized) in .nib files
       –    Dynamically loaded
       –    Objects deserialized at load time




                    www.exoplatform.com - Copyright 2012 eXo Platform   30
Xcode




                          DEMO




        www.exoplatform.com - Copyright 2012 eXo Platform   31
iOS




www.exoplatform.com - Copyright 2012 eXo Platform   32
iOS – Layered architecture

C libraries and system calls


Core services (C libraries and Objective-C frameworks)


Media Layer (C libraries and Objective-C frameworks)


Cocoa touch
      Foundation framework
      UIKit



               www.exoplatform.com - Copyright 2012 eXo Platform   33
iOS – Design Patterns



                       MVC Pattern



                    Delegate Pattern



                 Target/Action Pattern




           www.exoplatform.com - Copyright 2012 eXo Platform   34
iOS – MVC Pattern



       Model                                         View




                       Controller




           www.exoplatform.com - Copyright 2012 eXo Platform   35
iOS – MVC Pattern

Model
        –   Manages the app data and state
        –   No concerned with UI or presentation
        –   Often persists somewhere
        –   Same model should be reusable, unchanged in different
            interfaces.




                  www.exoplatform.com - Copyright 2012 eXo Platform   36
iOS – MVC Pattern

View
       –   Present the Model to the user in an appropriate interface
       –   Allows user to manipulate data
       –   Does not store any data
       –   Easily reusable & configurable to display different data




                  www.exoplatform.com - Copyright 2012 eXo Platform    37
iOS – MVC Pattern

Controller
      –      Intermediary between Model & View
      –      Updates the view when the model changes
      –      Updates the model when the user manipulates the view
      –      Typically where the app logic lives.




                    www.exoplatform.com - Copyright 2012 eXo Platform   38
iOS – Delegation Pattern
Control passed to delegate objects to perform application specific
  behavior


Avoids need to subclass complex objects


Many UIKit classes use delegates
       –    UIApplication
       –    UITableView
       –    UITextField




                   www.exoplatform.com - Copyright 2012 eXo Platform   39
iOS – Target/Action Pattern

When event occurs, action is invoked on target
 object

                                          Target: myObject
    sayHello                              Action: @selector(sayHello)
                                          Event: UIControlEventTouchUpInside




                                                                   Controller

               www.exoplatform.com - Copyright 2012 eXo Platform                40
References



Training for newcomer of Mobile team -
http://int.exoplatform.org/portal/g/:spaces:mobile/mobile/local._wiki.WikiPortl
et/group/spaces/mobile/iOS_Training



Jonathan Lehr -
http://jonathanlehr.files.wordpress.com/2009/09/objective-c-and-java.pdf



stanford.edu - http://www.stanford.edu/class/cs193p/cgi-bin/drupal/




                     www.exoplatform.com - Copyright 2012 eXo Platform            41
Questions?




www.exoplatform.com - Copyright 2012 eXo Platform   42

Mais conteúdo relacionado

Destaque

Destaque (7)

Advance jquery-plugin
Advance jquery-pluginAdvance jquery-plugin
Advance jquery-plugin
 
Hadoop
HadoopHadoop
Hadoop
 
E xo mobile_overview_best_practice_in_mobile_application_design
E xo mobile_overview_best_practice_in_mobile_application_designE xo mobile_overview_best_practice_in_mobile_application_design
E xo mobile_overview_best_practice_in_mobile_application_design
 
Wg11 automaive
Wg11 automaiveWg11 automaive
Wg11 automaive
 
Jquery
JqueryJquery
Jquery
 
Magento
MagentoMagento
Magento
 
Memory and runtime analysis
Memory and runtime analysisMemory and runtime analysis
Memory and runtime analysis
 

Semelhante a I os

Zero redeployment with JRebel
Zero redeployment with JRebelZero redeployment with JRebel
Zero redeployment with JRebelMinh Hoang
 
Ios fundamentals with ObjectiveC
Ios fundamentals with ObjectiveCIos fundamentals with ObjectiveC
Ios fundamentals with ObjectiveCMadusha Perera
 
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)Netcetera
 
Write native iPhone applications using Eclipse CDT
Write native iPhone applications using Eclipse CDTWrite native iPhone applications using Eclipse CDT
Write native iPhone applications using Eclipse CDTAtit Patumvan
 
CRaSH: the shell for the Java Platform
CRaSH: the shell for the Java PlatformCRaSH: the shell for the Java Platform
CRaSH: the shell for the Java Platformjviet
 
Find your own iOS kernel bug
Find your own iOS kernel bugFind your own iOS kernel bug
Find your own iOS kernel bugGustavo Martinez
 
Cross-Platform Mobile Development in Visual Studio
Cross-Platform Mobile Development in Visual StudioCross-Platform Mobile Development in Visual Studio
Cross-Platform Mobile Development in Visual Studiobryan costanich
 
Java Semimar Slide (Cetpa)
Java Semimar Slide (Cetpa)Java Semimar Slide (Cetpa)
Java Semimar Slide (Cetpa)Pratima Parida
 
Java Semimar Slide (Cetpa)
Java Semimar Slide (Cetpa)Java Semimar Slide (Cetpa)
Java Semimar Slide (Cetpa)Pratima Parida
 
Browser exploitation SEC-T 2019 stockholm
Browser exploitation SEC-T 2019 stockholmBrowser exploitation SEC-T 2019 stockholm
Browser exploitation SEC-T 2019 stockholmJameel Nabbo
 
Разработка кросс-платформенного кода между iPhone < -> Windows с помощью o...
Разработка кросс-платформенного кода между iPhone < -> Windows с помощью o...Разработка кросс-платформенного кода между iPhone < -> Windows с помощью o...
Разработка кросс-платформенного кода между iPhone < -> Windows с помощью o...Yandex
 
OCL'16 slides: Models from Code or Code as a Model?
OCL'16 slides: Models from Code or Code as a Model?OCL'16 slides: Models from Code or Code as a Model?
OCL'16 slides: Models from Code or Code as a Model?Antonio García-Domínguez
 
Cocoa for Web Developers
Cocoa for Web DevelopersCocoa for Web Developers
Cocoa for Web Developersgeorgebrock
 
Creating a Plug-In Architecture
Creating a Plug-In ArchitectureCreating a Plug-In Architecture
Creating a Plug-In Architectureondrejbalas
 
Using the Android Native Development Kit (NDK)
Using the Android Native Development Kit (NDK)Using the Android Native Development Kit (NDK)
Using the Android Native Development Kit (NDK)DroidConTLV
 

Semelhante a I os (20)

Zero redeployment with JRebel
Zero redeployment with JRebelZero redeployment with JRebel
Zero redeployment with JRebel
 
Ios fundamentals with ObjectiveC
Ios fundamentals with ObjectiveCIos fundamentals with ObjectiveC
Ios fundamentals with ObjectiveC
 
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
 
Introduction to Objective - C
Introduction to Objective - CIntroduction to Objective - C
Introduction to Objective - C
 
Write native iPhone applications using Eclipse CDT
Write native iPhone applications using Eclipse CDTWrite native iPhone applications using Eclipse CDT
Write native iPhone applications using Eclipse CDT
 
CRaSH: the shell for the Java Platform
CRaSH: the shell for the Java PlatformCRaSH: the shell for the Java Platform
CRaSH: the shell for the Java Platform
 
Find your own iOS kernel bug
Find your own iOS kernel bugFind your own iOS kernel bug
Find your own iOS kernel bug
 
Cross-Platform Mobile Development in Visual Studio
Cross-Platform Mobile Development in Visual StudioCross-Platform Mobile Development in Visual Studio
Cross-Platform Mobile Development in Visual Studio
 
Java Semimar Slide (Cetpa)
Java Semimar Slide (Cetpa)Java Semimar Slide (Cetpa)
Java Semimar Slide (Cetpa)
 
Java Semimar Slide (Cetpa)
Java Semimar Slide (Cetpa)Java Semimar Slide (Cetpa)
Java Semimar Slide (Cetpa)
 
Browser exploitation SEC-T 2019 stockholm
Browser exploitation SEC-T 2019 stockholmBrowser exploitation SEC-T 2019 stockholm
Browser exploitation SEC-T 2019 stockholm
 
Разработка кросс-платформенного кода между iPhone < -> Windows с помощью o...
Разработка кросс-платформенного кода между iPhone < -> Windows с помощью o...Разработка кросс-платформенного кода между iPhone < -> Windows с помощью o...
Разработка кросс-платформенного кода между iPhone < -> Windows с помощью o...
 
OCL'16 slides: Models from Code or Code as a Model?
OCL'16 slides: Models from Code or Code as a Model?OCL'16 slides: Models from Code or Code as a Model?
OCL'16 slides: Models from Code or Code as a Model?
 
Cocoa for Web Developers
Cocoa for Web DevelopersCocoa for Web Developers
Cocoa for Web Developers
 
iOS Application Development
iOS Application DevelopmentiOS Application Development
iOS Application Development
 
Creating a Plug-In Architecture
Creating a Plug-In ArchitectureCreating a Plug-In Architecture
Creating a Plug-In Architecture
 
Srgoc dotnet
Srgoc dotnetSrgoc dotnet
Srgoc dotnet
 
Csharp dot net
Csharp dot netCsharp dot net
Csharp dot net
 
How to Build & Use OpenCL on OpenCV & Android NDK
How to Build & Use OpenCL on OpenCV & Android NDKHow to Build & Use OpenCL on OpenCV & Android NDK
How to Build & Use OpenCL on OpenCV & Android NDK
 
Using the Android Native Development Kit (NDK)
Using the Android Native Development Kit (NDK)Using the Android Native Development Kit (NDK)
Using the Android Native Development Kit (NDK)
 

Mais de adm_exoplatform

Mais de adm_exoplatform (8)

Development withforce
Development withforceDevelopment withforce
Development withforce
 
Jquery ui
Jquery uiJquery ui
Jquery ui
 
Cmsms
CmsmsCmsms
Cmsms
 
Java application server in the cloud
Java application server in the cloudJava application server in the cloud
Java application server in the cloud
 
Jvm mbeans jmxtran
Jvm mbeans jmxtranJvm mbeans jmxtran
Jvm mbeans jmxtran
 
Git training
Git trainingGit training
Git training
 
Cluster mode and plf cluster
Cluster mode and plf clusterCluster mode and plf cluster
Cluster mode and plf cluster
 
Cluster mode and plf cluster
Cluster mode and plf clusterCluster mode and plf cluster
Cluster mode and plf cluster
 

Último

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
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
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
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
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 

Último (20)

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
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
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 

I os

  • 1. How to develop an iOS application Objective C – Xcode – iOS Le Thanh Quang Mobile team April 19th 2012
  • 2. Agenda Objective-C in brief Xcode iOS frameworks www.exoplatform.com - Copyright 2012 eXo Platform 2
  • 4. Objective-C – What is it? Simple extension of the C language Adds object-oriented capabilities to C language Runtime system (C library) Dynamic typing Dynamic binding GCC/Clang compiler supports both C and Objective-C Apple donated Objective-C for GNU project (open source) www.exoplatform.com - Copyright 2012 eXo Platform 4
  • 5. Objective-C – Who use? Apple Inc. Mac OS X developers Cocoa framework Core animation, Core data, etc iOS developers Cocoa touch framework Core animation, Core data, etc www.exoplatform.com - Copyright 2012 eXo Platform 5
  • 6. Objective-C – Why should I (Java developer) care? Make up your mind with new code designs iPhone/iPad devices become popular rich user agents in enterprise market eXo Platform 3.5, cloud-workspaces.com are integrated with iOS based devices and Android family Play around for fun or profit in free time ;) www.exoplatform.com - Copyright 2012 eXo Platform 6
  • 7. Objective-C – History Appeared in 1983 Designed by Tom Love & Brad Fox Major implementations GCC, Clang Influenced by Smalltalk, C OS Cross-platform www.exoplatform.com - Copyright 2012 eXo Platform 7
  • 8. Objective-C and Java Java Almost everywhere … except iPhone Objective-C Platform Mac OS X iPhone, iPad, ... www.exoplatform.com - Copyright 2012 eXo Platform 8
  • 9. Objective-C and Java Message Syntax Java myString.toString() Objective-C * Square brackets for message expressions [myString description] www.exoplatform.com - Copyright 2012 eXo Platform 9
  • 10. Objective-C and Java Method arguments Java person.setFirstName(“Fred”) Objective-C * Arguments are delimited by colons [person setFirstName:@”Fred”] www.exoplatform.com - Copyright 2012 eXo Platform 10
  • 11. Objective-C and Java Object Data types Java Employee emp = new Employee(); Objective-C * Objective-C objects are dynamically allocated structs Employee *emp = [[Employee alloc] init]; * Providing generic object type, id id emp2 = [[Employee alloc] init]; www.exoplatform.com - Copyright 2012 eXo Platform 11
  • 12. Objective-C and Java Object Data types Java * Constructors Employee emp = new Employee(); Objective-C Employee *emp = [[Employee alloc] init]; * Creation methods are just methods * Calls to super can occur anywhere within a method * Inheritance is straight-forward * Memory allocations and initialization are separate steps www.exoplatform.com - Copyright 2012 eXo Platform 12
  • 13. Objective-C and Java Prefix vs Package path Java java.lang.String s = new String(“hello”); Objective-C * Objective-C doesn't provide namespaces * Frameworks and libraries use prefixes by convention to avoid collision NSString *s = [NSString alloc] initWithString:@”Hi”]; ==> NS is prefix for classes of Foundation Framework. www.exoplatform.com - Copyright 2012 eXo Platform 13
  • 14. Objective-C and Java Method prototypes Java public void sayHello() { … } Objective-C * Methods declared in .h file, implemented in .m * Instance methods prefixed with - * Class methods prefixed with + Ex: // Method declarations - (id)init; - (id)alloc; www.exoplatform.com - Copyright 2012 eXo Platform 14
  • 15. Objective-C and Java Method prototypes Objective-C * No method overloading * Runtime system looks up methods by name rather than signatures * Method names can be composed of multiple sections Ex: - (void)addEmployee:(Employee *)emp withTitle: (NSString *)title Name of method is addEmployee:withTitle www.exoplatform.com - Copyright 2012 eXo Platform 15
  • 16. Objective-C and Java Class Java ... Objective-C www.exoplatform.com - Copyright 2012 eXo Platform 16
  • 17. Objective-C and Java Anatomy of Class Declaration www.exoplatform.com - Copyright 2012 eXo Platform 17
  • 18. Objective-C Class Implementation www.exoplatform.com - Copyright 2012 eXo Platform 18
  • 19. Objective-C and Java Class Java ... Objective-C www.exoplatform.com - Copyright 2012 eXo Platform 19
  • 20. Objective-C – Memory management * Reference counting – (id)retain; // increase retain count – (id)release; // decrease retain count – (id)autorelease; // release with a delay – (void)dealloc; // call by release when retain count = 1 * Creation methods set retain count to 1 – Creation methods whose names start with alloc or new or contain copy – Those who call creation methods MUST call either release or autorelease also – Never call dealloc directly www.exoplatform.com - Copyright 2012 eXo Platform 20
  • 21. Objective-C – Memory management www.exoplatform.com - Copyright 2012 eXo Platform 21
  • 22. Objective-C – Categories www.exoplatform.com - Copyright 2012 eXo Platform 22
  • 23. Objective-C – Using category www.exoplatform.com - Copyright 2012 eXo Platform 23
  • 24. Objective-C – Blocks A block of code – A sequence of statements inside {} – Start with the magical character caret ^ Ex: [aDictionary enumerateKeysAndObjectsUsingBlock:^(id key, id value, BOOL *stop) { NSLog(@“value for key %@ is %@”, key, value); if ([@“ENOUGH” isEqualToString:key]) { *stop = YES; } }]; www.exoplatform.com - Copyright 2012 eXo Platform 24
  • 25. Objective-C – Blocks A block of code – Can use local variables declared before the block inside the block – But they are read only! Ex: double stopValue = 53.5; [aDictionary enumerateKeysAndObjectsUsingBlock:^(id key, id value, BOOL *stop) { NSLog(@“value for key %@ is %@”, key, value); if ([@“ENOUGH” isEqualToString:key] || ([value doubleValue] == stopValue)) { *stop = YES; stoppedEarly = YES; // ILLEGAL } }]; www.exoplatform.com - Copyright 2012 eXo Platform 25
  • 26. Objective-C – Blocks When do we use blocks in iOS? – Enumeration – View Animations – Sorting (sort this thing using a block as the comparison method) – Notification (when something happens, execute this block) – Error handlers (if an error happens while doing this, execute this block) – Completion handlers (when you are done doing this, execute this block) And a super-important use: Multithreading www.exoplatform.com - Copyright 2012 eXo Platform 26
  • 28. Xcode IDE for iPhone projects – Build – Run (Simulator, device) – Debug – Source code management (SCM) – Documentation www.exoplatform.com - Copyright 2012 eXo Platform 28
  • 29. Xcode Automatically maintain build scripts Display logical grouping of files No package paths By default, groups not mapped to folder structure Resources Automatically bundled with executable Frameworks Linked at compile time; no classpath needed www.exoplatform.com - Copyright 2012 eXo Platform 29
  • 30. Xcode - Interface Builder Visual GUI design tool Doesn't generate code Working with “freeze-dried” objects – Archived (serialized) in .nib files – Dynamically loaded – Objects deserialized at load time www.exoplatform.com - Copyright 2012 eXo Platform 30
  • 31. Xcode DEMO www.exoplatform.com - Copyright 2012 eXo Platform 31
  • 32. iOS www.exoplatform.com - Copyright 2012 eXo Platform 32
  • 33. iOS – Layered architecture C libraries and system calls Core services (C libraries and Objective-C frameworks) Media Layer (C libraries and Objective-C frameworks) Cocoa touch Foundation framework UIKit www.exoplatform.com - Copyright 2012 eXo Platform 33
  • 34. iOS – Design Patterns MVC Pattern Delegate Pattern Target/Action Pattern www.exoplatform.com - Copyright 2012 eXo Platform 34
  • 35. iOS – MVC Pattern Model View Controller www.exoplatform.com - Copyright 2012 eXo Platform 35
  • 36. iOS – MVC Pattern Model – Manages the app data and state – No concerned with UI or presentation – Often persists somewhere – Same model should be reusable, unchanged in different interfaces. www.exoplatform.com - Copyright 2012 eXo Platform 36
  • 37. iOS – MVC Pattern View – Present the Model to the user in an appropriate interface – Allows user to manipulate data – Does not store any data – Easily reusable & configurable to display different data www.exoplatform.com - Copyright 2012 eXo Platform 37
  • 38. iOS – MVC Pattern Controller – Intermediary between Model & View – Updates the view when the model changes – Updates the model when the user manipulates the view – Typically where the app logic lives. www.exoplatform.com - Copyright 2012 eXo Platform 38
  • 39. iOS – Delegation Pattern Control passed to delegate objects to perform application specific behavior Avoids need to subclass complex objects Many UIKit classes use delegates – UIApplication – UITableView – UITextField www.exoplatform.com - Copyright 2012 eXo Platform 39
  • 40. iOS – Target/Action Pattern When event occurs, action is invoked on target object Target: myObject sayHello Action: @selector(sayHello) Event: UIControlEventTouchUpInside Controller www.exoplatform.com - Copyright 2012 eXo Platform 40
  • 41. References Training for newcomer of Mobile team - http://int.exoplatform.org/portal/g/:spaces:mobile/mobile/local._wiki.WikiPortl et/group/spaces/mobile/iOS_Training Jonathan Lehr - http://jonathanlehr.files.wordpress.com/2009/09/objective-c-and-java.pdf stanford.edu - http://www.stanford.edu/class/cs193p/cgi-bin/drupal/ www.exoplatform.com - Copyright 2012 eXo Platform 41

Notas do Editor

  1. Objective-C in brief Xcode MVC, Delegate and action-target patterns Cocoa Touch Frameworks Blocks, multithreading, categories
  2. * Objective-C is a superset of C Objective-C, being a C derivative, inherits all of C's features. There are a few exceptions but they don't really deviate from what C offers as a language. * Likewise, the language can be implemented on top of existing C compilers (in GCC, first as a preprocessor, then as a module) rather than as a new compiler. This allows Objective-C to leverage the huge existing collection of C code, libraries, tools, etc. Existing C libraries can be wrapped in Objective-C wrappers to provide an OO-style interface. In this aspect, it is similar to GObject library and Vala language, which are widely used in development of GTK applications. * Starting in 2005, Apple has made extensive use of LLVM in a number of commercial systems,[4] including the iPhone development kit and Xcode 3.1.
  3. * Today, objective-C is used primarily on Apple's Mac OS X and iOS * It is the primary language used for Apple's Cocoa API *
  4. * Objective-C includes many concept and pattern which are useful for developers to know. *
  5. Watch a video illustrate how to create an iOS application by Xcode
  6. Watch a video illustrate how to create an iOS application by Xcode