SlideShare una empresa de Scribd logo
1 de 129
Descargar para leer sin conexión
iPhone
         Objective-C, UIKit




                              bofeng@corp.netease.com
                                             @vonbo
Agenda

• overview
• objective-c
• iPhone UIKit
overview
First iPhone App


• Hello world!
Things we have



• Hello world!
• xcode SDK
•       & test with Simulator

• test with iPhone/iPod touch ($99)
•         appstore

•
iPhone VS Android
objective-c
Objective C
•
•
•   runtime
•   foudation framework: values and collection classes
•
•   category
•   protocol
Sample Code
   hello world
objective c
•   @

    •   @interface, @implementation, @class

    •   @property, @synthesize

    •   @protocol

    •   NSString* str = @”hello world”

•                       [receiver message]

•           C                 C++
Sample Code
  class and message
runtime
•   id
•   class & className
•   respondsToSelector
•   performSelector
•   isKindOfClass (super class included)
•   isMemberOfClass
•   @selector
@selector


• SEL
•       C++
action
CGRect rect = CGRectMake(20, 20, 100, 30);
UIButton* myButton = [UIButton
buttonWithType:UIButtonTypeRoundedRect];
myButton.frame = rect;
[myButton setTitle:@"my button"
forState:UIControlStateNormal];
[myButton addTarget:self action:@selector(btnClick:)
forControlEvents : UIControlEventTouchUpInside];
[self.view addSubview:myButton];
Sample
runtime & selector
Foundation Framework
• Value and Collection Classes
• User defaults
• Archiving
• Task, timers, thread
• File system, I/0
• etc ...
Value and Collection
           Classes
•   NSString & NSMutableString
•   NSArray & NSMutableArray
•   NSDictionary & NSMutableDictionary
•   NSSet & NSMutableSet
•   NSNumber [a obj-c object wrapper for basic C
    type]
    •   (NSNumber* num = [NSNumber
        numberWithInt:3])
Sample Code
  collection classes
•                   alloc   new

•   alloc&dealloc    C++ new&delete

•   but with ...
•           alloc   new         copy
                                   1.
                                          retain

     release
•                                0
    Obj-C                       dealloc
                      dealloc
                                        dealloc
Sample Code
  “           ”      ...
 memory management
Getter & Setter
  @property & @synthesize
•       new   alloc    copy
                                 1.

    release

•
                      retain release
but how to solve this ?
- (Person*) getChild {
    Person* child = [[Person alloc] init];
    [child setName:@”xxxx”];
    ....
    // will return ... [child release] or not ?
    return child;
}
Autorelease
• NSAutoreleasePool* pool ...
• [object autorelease]
•                     autorelease

  NSAutoreleasePool

  release
That’s why create pool
            first ...
int main(int argc, char* argv[]) {
    NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
    // put your own code here ...
    [pool release];
}
how to solve this ?
- (Person*) getChild {
    Person* child = [[Person alloc] init];
    [child setName:@”xxxx”];
    ....
    // will return ... [child release] or not ?
    return [child autorelease];
}
Autorelease Pool
•
    •                    NSMutableArray pool
    •   autorelease             Array
    •             pool            Array
        release

•                             autorelease pool
           autorelease
    pool                          pool
Autorelease Pool Stack
NSAutoreleasePool* poolFirst ..
for (int i=0; i < 10000; i++) {
    NSAutoreleasePool* poolSecond ...
    // have some autorelease object
    // [object autorelease]
    [poolSecond release];
}
// other code
[poolFirst release];
Autorelease Pool
•
    •   NSAutoreleasePool


    •                 alloc            release
    •               Autorelease pool      retain
        autorelease   [pool retain] or [pool autorelease]
    •   AutoreleasePool                                     “
                   ”
    •               pool             pool
                    iphone
          release        autorelease
•   new   alloc    copy
                  1.
                     release autorelease
•
                    1

     [NSString stringWithString:@”objc”]
•
                  retain release
Category
Sample Code
   category
NSString   Class
Cluster ...
Sample Code
something about class cluster ...
Category
•
•
•
Protocol
•   familiar with C++ virtual class
•   familiar with Java’s interface
•

•                          @optional
                     @required
              warning          required
protocol

@protocol TwoMethod
  - (void) oneMethod;
  - (void) anotherMethod;
@end
Class & Protocol
@interface MyClass : NSObject <TwoMethod> {
}
@end


@implementation MyClass
-(void) oneMethod {
    // oneMethod’s implementation
}
- (void) anotherMethod {
    // anotherMethod’s implementation
}
@end
Sample Code
   protocol
Objective C
•
•
•   runtime    id, @selector, respondsToSelector ...
•   foudation framework: values and collection classes
•
•   category                  class cluster “      ”
•   protocol
Using Objective-C Now !

• without mac
• ubuntu:
  • sudo apt-get install gnustep gnustep-devel
  • bash /usr/share/GNUstep/Makefiles/
    GNUstep.sh
  • GNUmakefile
• http://forum.ubuntu.org.cn/viewtopic.php?
  t=190168
iPhone UIKit
iPhone Application
•           &
• MVC
• Views (design & life cycle)
• Navigation based & Tab Bar based application
• very important TableView
•
• Web service
UIApplication
•   Every application must have exactly one instance of
    UIApplication (or a subclass of UIApplication). When
    an application is launched, the UIApplicationMain
    function is called; among its other tasks, this
    function create a singleton UIApplication object.

•   The application object is typically assigned a
    delegate, an object that the application informs of
    significant runtime events—for example, application
    launch, low-memory warnings, and application
    termination—giving it an opportunity to respond
    appropriately.
UIApplicationMain

• delegateClassName
 • Specify nil if you load the delegate object
    from your application’s main nib file.
• from Info.plist get main nib file
• from main nib file get the application’s
  delegate
UIControl

• UILabel
• UIButton
• UITableView
• UINavigatorBar
• ...
- design time
Demo
button click
Without IB ?
create a button and bind event by code
Views
•   View                            view
    superview                   subviews
•       iphone app             window    Views
    window     window                   view (top level)

•   view
    •   - (void)addSubview:(UIView *)view;
    •   - (void)removeFromSuperview;
•   Superviews retain their subviews
•   UIView            CGRect                 CGPoint
      CGSize
View’s life cycle & hook
        function
•   initWithNibName:bundle
•   viewDidLoad
•   viewWillAppear
•   viewWillDisappear
•   ...maybe viewDidUnload
•   hook function
    •   shouldAutorotateToInterfaceOrientation
    •   didReceiveMemoryWarning
Navigation Controller
UINavigationController

•   manages the currently displayed screens using the
    navigation stack
•   at the bottom of this stack is the root view controller
•   at the top of the stack is the view controller currently
    being displayed
•   method:
    •   pushViewController:animated:
    •   popViewControllerAnimated:
Demo
UINavigationController
TabBar Controller
UITabBarController
• implements a specialized view controller that
  manages a radio-style selection interface
• When the user selects a specific tab, the tab
  bar controller displays the root view of the
  corresponding view controller, replacing any
  previous views
• init with an array (has many view controllers)
Demo
UITabBarController
Combine


•              UI

    • TabBarController Based +
      NavigationController
Demo
Combine UITabBarController &
   UINavigationController
TableView

• display a list of data
 • Single column, multiple rows
 • Vertical scrolling
• Powerful and ubiquitous in iPhone
  applications
Display data in Table View
•
    •    Table views display a list of data, so use an array
    •    [myTableView setList:myListOfStuff];
    •
        •   All data is loaded upfront
        •   All data stays in memory
•
    •    Another object provides data to the table view
        •   Not all at once
        •   Just as it’s needed for display
    •    Like a delegate, but purely data-oriented
Demo
UITableView <UITableViewDataSource>
Selection
Demo
UITableView <UITableViewDelegate>
UITabBar + UINavigation + UITableView !

NavigationController

                                 TableViewController




                                 TabBarController
Demo
UITabBar + UINavigation + UITableView
• Propery Lists, NSUserDefaults
• SQLite
• Core Data
SandBox

• Why keep applications separate?
 • Security
 • Privacy
 • Cleanup after deleting an app
Sample: /Users/xxx/library/Application Support/iPhone Simulator/4.0/Applications
Property Lists
•       Convenient way to store a small amount of data
    •    Arrays, dictionaries, strings, numbers, dates, raw data
    •    Human-readable XML or binary format
•   NSUserDefaults class uses property lists under the hood
•   When Not to Use Property Lists

    •    More than a few hundred KB of data

    •    Custom object types

    •    Multiple writers (e.g. not ACID)
Demo
Save data with NSUserDefaults
SQLite
•   Complete SQL database in an ordinary file
•   Simple, compact, fast, reliable
•   No server
•   Great for embedded devices
    •   Included on the iPhone platform
•   When Not to Use SQLite
    •   Multi-gigabyte databases
    •   High concurrency (multiple writers)
    •   Client-server applications
SQLite Obj-C Wrapper

•   http://code.google.com/p/flycode/source/browse/
    trunk/fmdb

•   A query maybe like this:

    •   [dbconn executeQuery:@"select * from call"]
Using Web Service
•   Two Common ways:
•   XML
    •   libxml2
        •   Tree-based: easy to parse, entire tree in memory
        •   Event-driven: less memory, more complex to manage state
    •   NSXMLParser
        •   Event-driven API: simpler but less powerful than libxml2
•   JSON
    •   Open source json-framework wrapper for Objective-C
    •   http://code.google.com/p/json-framework/
NSURLConnection
•   NSMutableURLRequest
•   - connectionWithRequest: delegate
•   delegate method:
    •   – connection:didReceiveResponse:
    •   – connection:didReceiveData:
    •   – connection:didFailWithError:
    •   – connectionDidFinishLoading:
Demo
use json-framework and NSURLConnection with hi-api
iPhone Application

•              &
•   MVC
•   Views (design & life cycle)
•   Navigation based & Tab Bar based application
    & TableView
•                        (sandbox, property list,
    sqlite)
•   Web service
•       Objective-C
•       The iPhone Developer’s Cookbook
•       Programming in Objective-C 2.0
•
•           Stanford iPhone dev course
    •       iTunes iTune Store    cs193p
                       mac windows
Q &A
The End

Más contenido relacionado

La actualidad más candente

iPhone Memory Management
iPhone Memory ManagementiPhone Memory Management
iPhone Memory ManagementVadim Zimin
 
User defined-functions-cassandra-summit-eu-2014
User defined-functions-cassandra-summit-eu-2014User defined-functions-cassandra-summit-eu-2014
User defined-functions-cassandra-summit-eu-2014Robert Stupp
 
Memory Management on iOS
Memory Management on iOSMemory Management on iOS
Memory Management on iOSMake School
 
ARCでめちゃモテiOSプログラマー
ARCでめちゃモテiOSプログラマーARCでめちゃモテiOSプログラマー
ARCでめちゃモテiOSプログラマーSatoshi Asano
 
Memory management in Objective C
Memory management in Objective CMemory management in Objective C
Memory management in Objective CNeha Gupta
 
JavaScript!
JavaScript!JavaScript!
JavaScript!RTigger
 
Moving from JFreeChart to JavaFX with JavaFX Chart Extensions
Moving from JFreeChart to JavaFX with JavaFX Chart ExtensionsMoving from JFreeChart to JavaFX with JavaFX Chart Extensions
Moving from JFreeChart to JavaFX with JavaFX Chart ExtensionsBruce Schubert
 
Getting started with jQuery
Getting started with jQueryGetting started with jQuery
Getting started with jQueryGill Cleeren
 
Cassandra and materialized views
Cassandra and materialized viewsCassandra and materialized views
Cassandra and materialized viewsGrzegorz Duda
 
Multithreading on iOS
Multithreading on iOSMultithreading on iOS
Multithreading on iOSMake School
 
Mastering Java Bytecode With ASM - 33rd degree, 2012
Mastering Java Bytecode With ASM - 33rd degree, 2012Mastering Java Bytecode With ASM - 33rd degree, 2012
Mastering Java Bytecode With ASM - 33rd degree, 2012Anton Arhipov
 
iOS App with Parse.com as RESTful Backend
iOS App with Parse.com as RESTful BackendiOS App with Parse.com as RESTful Backend
iOS App with Parse.com as RESTful BackendStefano Zanetti
 

La actualidad más candente (19)

Django at Scale
Django at ScaleDjango at Scale
Django at Scale
 
iPhone Memory Management
iPhone Memory ManagementiPhone Memory Management
iPhone Memory Management
 
User defined-functions-cassandra-summit-eu-2014
User defined-functions-cassandra-summit-eu-2014User defined-functions-cassandra-summit-eu-2014
User defined-functions-cassandra-summit-eu-2014
 
iOS 7 SDK特訓班
iOS 7 SDK特訓班iOS 7 SDK特訓班
iOS 7 SDK特訓班
 
Memory Management on iOS
Memory Management on iOSMemory Management on iOS
Memory Management on iOS
 
ARCでめちゃモテiOSプログラマー
ARCでめちゃモテiOSプログラマーARCでめちゃモテiOSプログラマー
ARCでめちゃモテiOSプログラマー
 
Memory management in Objective C
Memory management in Objective CMemory management in Objective C
Memory management in Objective C
 
Objective C Memory Management
Objective C Memory ManagementObjective C Memory Management
Objective C Memory Management
 
JavaScript!
JavaScript!JavaScript!
JavaScript!
 
XQuery Design Patterns
XQuery Design PatternsXQuery Design Patterns
XQuery Design Patterns
 
Moving from JFreeChart to JavaFX with JavaFX Chart Extensions
Moving from JFreeChart to JavaFX with JavaFX Chart ExtensionsMoving from JFreeChart to JavaFX with JavaFX Chart Extensions
Moving from JFreeChart to JavaFX with JavaFX Chart Extensions
 
jQuery Objects
jQuery ObjectsjQuery Objects
jQuery Objects
 
Getting started with jQuery
Getting started with jQueryGetting started with jQuery
Getting started with jQuery
 
Cassandra and materialized views
Cassandra and materialized viewsCassandra and materialized views
Cassandra and materialized views
 
Multithreading on iOS
Multithreading on iOSMultithreading on iOS
Multithreading on iOS
 
iOS Memory Management
iOS Memory ManagementiOS Memory Management
iOS Memory Management
 
Ios - Introduction to memory management
Ios - Introduction to memory managementIos - Introduction to memory management
Ios - Introduction to memory management
 
Mastering Java Bytecode With ASM - 33rd degree, 2012
Mastering Java Bytecode With ASM - 33rd degree, 2012Mastering Java Bytecode With ASM - 33rd degree, 2012
Mastering Java Bytecode With ASM - 33rd degree, 2012
 
iOS App with Parse.com as RESTful Backend
iOS App with Parse.com as RESTful BackendiOS App with Parse.com as RESTful Backend
iOS App with Parse.com as RESTful Backend
 

Destacado

self and super in objc
self and super in objcself and super in objc
self and super in objcVonbo
 
よくわかるオンドゥル語
よくわかるオンドゥル語よくわかるオンドゥル語
よくわかるオンドゥル語S Akai
 
Defnydd trydan Ysgol y Frenni
Defnydd trydan Ysgol y FrenniDefnydd trydan Ysgol y Frenni
Defnydd trydan Ysgol y FrenniMrs Serena Davies
 
Method Shelters : Another Way to Resolve Class Extension Conflicts
Method Shelters : Another Way to Resolve Class Extension Conflicts Method Shelters : Another Way to Resolve Class Extension Conflicts
Method Shelters : Another Way to Resolve Class Extension Conflicts S Akai
 
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみたスマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみたTaro Matsuzawa
 
Romafs
RomafsRomafs
RomafsS Akai
 
RubyistのためのObjective-C入門
RubyistのためのObjective-C入門RubyistのためのObjective-C入門
RubyistのためのObjective-C入門S Akai
 
Qcon beijing 2010
Qcon beijing 2010Qcon beijing 2010
Qcon beijing 2010Vonbo
 
Objective-C Survives
Objective-C SurvivesObjective-C Survives
Objective-C SurvivesS Akai
 
Présentation gnireenigne
Présentation   gnireenignePrésentation   gnireenigne
Présentation gnireenigneCocoaHeads.fr
 
Http Live Streaming Intro
Http Live Streaming IntroHttp Live Streaming Intro
Http Live Streaming IntroVonbo
 
Http live streaming technical presentation
Http live streaming technical presentationHttp live streaming technical presentation
Http live streaming technical presentationBuddhi
 
Mobile Movies with HTTP Live Streaming (CocoaConf DC, March 2013)
Mobile Movies with HTTP Live Streaming (CocoaConf DC, March 2013)Mobile Movies with HTTP Live Streaming (CocoaConf DC, March 2013)
Mobile Movies with HTTP Live Streaming (CocoaConf DC, March 2013)Chris Adamson
 

Destacado (15)

self and super in objc
self and super in objcself and super in objc
self and super in objc
 
よくわかるオンドゥル語
よくわかるオンドゥル語よくわかるオンドゥル語
よくわかるオンドゥル語
 
Defnydd trydan Ysgol y Frenni
Defnydd trydan Ysgol y FrenniDefnydd trydan Ysgol y Frenni
Defnydd trydan Ysgol y Frenni
 
Method Shelters : Another Way to Resolve Class Extension Conflicts
Method Shelters : Another Way to Resolve Class Extension Conflicts Method Shelters : Another Way to Resolve Class Extension Conflicts
Method Shelters : Another Way to Resolve Class Extension Conflicts
 
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみたスマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
 
Romafs
RomafsRomafs
Romafs
 
Tales@tdc
Tales@tdcTales@tdc
Tales@tdc
 
RubyistのためのObjective-C入門
RubyistのためのObjective-C入門RubyistのためのObjective-C入門
RubyistのためのObjective-C入門
 
Qcon beijing 2010
Qcon beijing 2010Qcon beijing 2010
Qcon beijing 2010
 
Objective-C Survives
Objective-C SurvivesObjective-C Survives
Objective-C Survives
 
Présentation gnireenigne
Présentation   gnireenignePrésentation   gnireenigne
Présentation gnireenigne
 
Http Live Streaming Intro
Http Live Streaming IntroHttp Live Streaming Intro
Http Live Streaming Intro
 
Http live streaming technical presentation
Http live streaming technical presentationHttp live streaming technical presentation
Http live streaming technical presentation
 
Mobile Movies with HTTP Live Streaming (CocoaConf DC, March 2013)
Mobile Movies with HTTP Live Streaming (CocoaConf DC, March 2013)Mobile Movies with HTTP Live Streaming (CocoaConf DC, March 2013)
Mobile Movies with HTTP Live Streaming (CocoaConf DC, March 2013)
 
HTTP Live Streaming
HTTP Live StreamingHTTP Live Streaming
HTTP Live Streaming
 

Similar a Beginning to iPhone development

MFF UK - Introduction to iOS
MFF UK - Introduction to iOSMFF UK - Introduction to iOS
MFF UK - Introduction to iOSPetr Dvorak
 
iOS Development: What's New
iOS Development: What's NewiOS Development: What's New
iOS Development: What's NewNascentDigital
 
Objective-C Is Not Java
Objective-C Is Not JavaObjective-C Is Not Java
Objective-C Is Not JavaChris Adamson
 
【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう
【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう
【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろうUnity Technologies Japan K.K.
 
iOS 101 - Xcode, Objective-C, iOS APIs
iOS 101 - Xcode, Objective-C, iOS APIsiOS 101 - Xcode, Objective-C, iOS APIs
iOS 101 - Xcode, Objective-C, iOS APIsSubhransu Behera
 
Connect.Tech- Swift Memory Management
Connect.Tech- Swift Memory ManagementConnect.Tech- Swift Memory Management
Connect.Tech- Swift Memory Managementstable|kernel
 
MFF UK - Advanced iOS Topics
MFF UK - Advanced iOS TopicsMFF UK - Advanced iOS Topics
MFF UK - Advanced iOS TopicsPetr Dvorak
 
Raffaele Rialdi
Raffaele RialdiRaffaele Rialdi
Raffaele RialdiCodeFest
 
Louis Loizides iOS Programming Introduction
Louis Loizides iOS Programming IntroductionLouis Loizides iOS Programming Introduction
Louis Loizides iOS Programming IntroductionLou Loizides
 
Cappuccino - A Javascript Application Framework
Cappuccino - A Javascript Application FrameworkCappuccino - A Javascript Application Framework
Cappuccino - A Javascript Application FrameworkAndreas Korth
 
iOS Programming Intro
iOS Programming IntroiOS Programming Intro
iOS Programming IntroLou Loizides
 
Working with Cocoa and Objective-C
Working with Cocoa and Objective-CWorking with Cocoa and Objective-C
Working with Cocoa and Objective-CKazunobu Tasaka
 
Android webinar class_4
Android webinar class_4Android webinar class_4
Android webinar class_4Edureka!
 
introduction to c #
introduction to c #introduction to c #
introduction to c #Sireesh K
 
Aplicações Assíncronas no Android com Coroutines e Jetpack
Aplicações Assíncronas no Android com Coroutines e JetpackAplicações Assíncronas no Android com Coroutines e Jetpack
Aplicações Assíncronas no Android com Coroutines e JetpackNelson Glauber Leal
 
Getting Started with XCTest and XCUITest for iOS App Testing
Getting Started with XCTest and XCUITest for iOS App TestingGetting Started with XCTest and XCUITest for iOS App Testing
Getting Started with XCTest and XCUITest for iOS App TestingBitbar
 
Pentesting iOS Apps - Runtime Analysis and Manipulation
Pentesting iOS Apps - Runtime Analysis and ManipulationPentesting iOS Apps - Runtime Analysis and Manipulation
Pentesting iOS Apps - Runtime Analysis and ManipulationAndreas Kurtz
 
Developing iOS REST Applications
Developing iOS REST ApplicationsDeveloping iOS REST Applications
Developing iOS REST Applicationslmrei
 

Similar a Beginning to iPhone development (20)

MFF UK - Introduction to iOS
MFF UK - Introduction to iOSMFF UK - Introduction to iOS
MFF UK - Introduction to iOS
 
iOS Development: What's New
iOS Development: What's NewiOS Development: What's New
iOS Development: What's New
 
Objective-C Is Not Java
Objective-C Is Not JavaObjective-C Is Not Java
Objective-C Is Not Java
 
【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう
【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう
【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう
 
iOS 101 - Xcode, Objective-C, iOS APIs
iOS 101 - Xcode, Objective-C, iOS APIsiOS 101 - Xcode, Objective-C, iOS APIs
iOS 101 - Xcode, Objective-C, iOS APIs
 
Connect.Tech- Swift Memory Management
Connect.Tech- Swift Memory ManagementConnect.Tech- Swift Memory Management
Connect.Tech- Swift Memory Management
 
MFF UK - Advanced iOS Topics
MFF UK - Advanced iOS TopicsMFF UK - Advanced iOS Topics
MFF UK - Advanced iOS Topics
 
Raffaele Rialdi
Raffaele RialdiRaffaele Rialdi
Raffaele Rialdi
 
Louis Loizides iOS Programming Introduction
Louis Loizides iOS Programming IntroductionLouis Loizides iOS Programming Introduction
Louis Loizides iOS Programming Introduction
 
Cappuccino - A Javascript Application Framework
Cappuccino - A Javascript Application FrameworkCappuccino - A Javascript Application Framework
Cappuccino - A Javascript Application Framework
 
iOS Programming Intro
iOS Programming IntroiOS Programming Intro
iOS Programming Intro
 
Working with Cocoa and Objective-C
Working with Cocoa and Objective-CWorking with Cocoa and Objective-C
Working with Cocoa and Objective-C
 
Android webinar class_4
Android webinar class_4Android webinar class_4
Android webinar class_4
 
introduction to c #
introduction to c #introduction to c #
introduction to c #
 
Aplicações Assíncronas no Android com Coroutines e Jetpack
Aplicações Assíncronas no Android com Coroutines e JetpackAplicações Assíncronas no Android com Coroutines e Jetpack
Aplicações Assíncronas no Android com Coroutines e Jetpack
 
Rubymotion talk
Rubymotion talkRubymotion talk
Rubymotion talk
 
React nativebeginner1
React nativebeginner1React nativebeginner1
React nativebeginner1
 
Getting Started with XCTest and XCUITest for iOS App Testing
Getting Started with XCTest and XCUITest for iOS App TestingGetting Started with XCTest and XCUITest for iOS App Testing
Getting Started with XCTest and XCUITest for iOS App Testing
 
Pentesting iOS Apps - Runtime Analysis and Manipulation
Pentesting iOS Apps - Runtime Analysis and ManipulationPentesting iOS Apps - Runtime Analysis and Manipulation
Pentesting iOS Apps - Runtime Analysis and Manipulation
 
Developing iOS REST Applications
Developing iOS REST ApplicationsDeveloping iOS REST Applications
Developing iOS REST Applications
 

Último

Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 

Último (20)

Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 

Beginning to iPhone development

  • 1. iPhone Objective-C, UIKit bofeng@corp.netease.com @vonbo
  • 4. First iPhone App • Hello world!
  • 5. Things we have • Hello world!
  • 6. • xcode SDK • & test with Simulator • test with iPhone/iPod touch ($99) • appstore •
  • 9. Objective C • • • runtime • foudation framework: values and collection classes • • category • protocol
  • 10. Sample Code hello world
  • 11.
  • 12. objective c • @ • @interface, @implementation, @class • @property, @synthesize • @protocol • NSString* str = @”hello world” • [receiver message] • C C++
  • 13.
  • 14.
  • 15.
  • 16.
  • 17. Sample Code class and message
  • 18. runtime • id • class & className • respondsToSelector • performSelector • isKindOfClass (super class included) • isMemberOfClass • @selector
  • 20.
  • 21.
  • 22. action CGRect rect = CGRectMake(20, 20, 100, 30); UIButton* myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; myButton.frame = rect; [myButton setTitle:@"my button" forState:UIControlStateNormal]; [myButton addTarget:self action:@selector(btnClick:) forControlEvents : UIControlEventTouchUpInside]; [self.view addSubview:myButton];
  • 24. Foundation Framework • Value and Collection Classes • User defaults • Archiving • Task, timers, thread • File system, I/0 • etc ...
  • 25. Value and Collection Classes • NSString & NSMutableString • NSArray & NSMutableArray • NSDictionary & NSMutableDictionary • NSSet & NSMutableSet • NSNumber [a obj-c object wrapper for basic C type] • (NSNumber* num = [NSNumber numberWithInt:3])
  • 26. Sample Code collection classes
  • 27. alloc new • alloc&dealloc C++ new&delete • but with ...
  • 28. alloc new copy 1. retain release • 0 Obj-C dealloc dealloc dealloc
  • 29. Sample Code “ ” ... memory management
  • 30. Getter & Setter @property & @synthesize
  • 31. new alloc copy 1. release • retain release
  • 32. but how to solve this ? - (Person*) getChild { Person* child = [[Person alloc] init]; [child setName:@”xxxx”]; .... // will return ... [child release] or not ? return child; }
  • 33. Autorelease • NSAutoreleasePool* pool ... • [object autorelease] • autorelease NSAutoreleasePool release
  • 34. That’s why create pool first ... int main(int argc, char* argv[]) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; // put your own code here ... [pool release]; }
  • 35. how to solve this ? - (Person*) getChild { Person* child = [[Person alloc] init]; [child setName:@”xxxx”]; .... // will return ... [child release] or not ? return [child autorelease]; }
  • 36. Autorelease Pool • • NSMutableArray pool • autorelease Array • pool Array release • autorelease pool autorelease pool pool
  • 37. Autorelease Pool Stack NSAutoreleasePool* poolFirst .. for (int i=0; i < 10000; i++) { NSAutoreleasePool* poolSecond ... // have some autorelease object // [object autorelease] [poolSecond release]; } // other code [poolFirst release];
  • 38. Autorelease Pool • • NSAutoreleasePool • alloc release • Autorelease pool retain autorelease [pool retain] or [pool autorelease] • AutoreleasePool “ ” • pool pool iphone release autorelease
  • 39. new alloc copy 1. release autorelease • 1 [NSString stringWithString:@”objc”] • retain release
  • 41. Sample Code category
  • 42. NSString Class Cluster ...
  • 43. Sample Code something about class cluster ...
  • 45. Protocol • familiar with C++ virtual class • familiar with Java’s interface • • @optional @required warning required
  • 46. protocol @protocol TwoMethod - (void) oneMethod; - (void) anotherMethod; @end
  • 47. Class & Protocol @interface MyClass : NSObject <TwoMethod> { } @end @implementation MyClass -(void) oneMethod { // oneMethod’s implementation } - (void) anotherMethod { // anotherMethod’s implementation } @end
  • 48. Sample Code protocol
  • 49. Objective C • • • runtime id, @selector, respondsToSelector ... • foudation framework: values and collection classes • • category class cluster “ ” • protocol
  • 50. Using Objective-C Now ! • without mac • ubuntu: • sudo apt-get install gnustep gnustep-devel • bash /usr/share/GNUstep/Makefiles/ GNUstep.sh • GNUmakefile • http://forum.ubuntu.org.cn/viewtopic.php? t=190168
  • 52. iPhone Application • & • MVC • Views (design & life cycle) • Navigation based & Tab Bar based application • very important TableView • • Web service
  • 53.
  • 54. UIApplication • Every application must have exactly one instance of UIApplication (or a subclass of UIApplication). When an application is launched, the UIApplicationMain function is called; among its other tasks, this function create a singleton UIApplication object. • The application object is typically assigned a delegate, an object that the application informs of significant runtime events—for example, application launch, low-memory warnings, and application termination—giving it an opportunity to respond appropriately.
  • 55.
  • 56.
  • 57. UIApplicationMain • delegateClassName • Specify nil if you load the delegate object from your application’s main nib file. • from Info.plist get main nib file • from main nib file get the application’s delegate
  • 58.
  • 59.
  • 60.
  • 61. UIControl • UILabel • UIButton • UITableView • UINavigatorBar • ...
  • 64. Without IB ? create a button and bind event by code
  • 65.
  • 66.
  • 67. Views • View view superview subviews • iphone app window Views window window view (top level) • view • - (void)addSubview:(UIView *)view; • - (void)removeFromSuperview; • Superviews retain their subviews • UIView CGRect CGPoint CGSize
  • 68. View’s life cycle & hook function • initWithNibName:bundle • viewDidLoad • viewWillAppear • viewWillDisappear • ...maybe viewDidUnload • hook function • shouldAutorotateToInterfaceOrientation • didReceiveMemoryWarning
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77. UINavigationController • manages the currently displayed screens using the navigation stack • at the bottom of this stack is the root view controller • at the top of the stack is the view controller currently being displayed • method: • pushViewController:animated: • popViewControllerAnimated:
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85. UITabBarController • implements a specialized view controller that manages a radio-style selection interface • When the user selects a specific tab, the tab bar controller displays the root view of the corresponding view controller, replacing any previous views • init with an array (has many view controllers)
  • 87. Combine • UI • TabBarController Based + NavigationController
  • 88.
  • 89.
  • 90. Demo Combine UITabBarController & UINavigationController
  • 91. TableView • display a list of data • Single column, multiple rows • Vertical scrolling • Powerful and ubiquitous in iPhone applications
  • 92.
  • 93.
  • 94. Display data in Table View • • Table views display a list of data, so use an array • [myTableView setList:myListOfStuff]; • • All data is loaded upfront • All data stays in memory • • Another object provides data to the table view • Not all at once • Just as it’s needed for display • Like a delegate, but purely data-oriented
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 104.
  • 105.
  • 107.
  • 109. UITabBar + UINavigation + UITableView ! NavigationController TableViewController TabBarController
  • 111. • Propery Lists, NSUserDefaults • SQLite • Core Data
  • 112. SandBox • Why keep applications separate? • Security • Privacy • Cleanup after deleting an app
  • 114.
  • 115.
  • 116. Property Lists • Convenient way to store a small amount of data • Arrays, dictionaries, strings, numbers, dates, raw data • Human-readable XML or binary format • NSUserDefaults class uses property lists under the hood • When Not to Use Property Lists • More than a few hundred KB of data • Custom object types • Multiple writers (e.g. not ACID)
  • 117.
  • 118.
  • 119. Demo Save data with NSUserDefaults
  • 120. SQLite • Complete SQL database in an ordinary file • Simple, compact, fast, reliable • No server • Great for embedded devices • Included on the iPhone platform • When Not to Use SQLite • Multi-gigabyte databases • High concurrency (multiple writers) • Client-server applications
  • 121.
  • 122. SQLite Obj-C Wrapper • http://code.google.com/p/flycode/source/browse/ trunk/fmdb • A query maybe like this: • [dbconn executeQuery:@"select * from call"]
  • 123.
  • 124. Using Web Service • Two Common ways: • XML • libxml2 • Tree-based: easy to parse, entire tree in memory • Event-driven: less memory, more complex to manage state • NSXMLParser • Event-driven API: simpler but less powerful than libxml2 • JSON • Open source json-framework wrapper for Objective-C • http://code.google.com/p/json-framework/
  • 125. NSURLConnection • NSMutableURLRequest • - connectionWithRequest: delegate • delegate method: • – connection:didReceiveResponse: • – connection:didReceiveData: • – connection:didFailWithError: • – connectionDidFinishLoading:
  • 126. Demo use json-framework and NSURLConnection with hi-api
  • 127. iPhone Application • & • MVC • Views (design & life cycle) • Navigation based & Tab Bar based application & TableView • (sandbox, property list, sqlite) • Web service
  • 128. Objective-C • The iPhone Developer’s Cookbook • Programming in Objective-C 2.0 • • Stanford iPhone dev course • iTunes iTune Store cs193p mac windows