How to develop an iOS application

1,580 views
1,513 views

Published on

This is slides for internal presentation in exo about iOS.

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

No Downloads
Views
Total views
1,580
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • Objective-C in brief Xcode MVC, Delegate and action-target patterns Cocoa Touch Frameworks Blocks, multithreading, categories
  • * 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.
  • * 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 *
  • Watch a video illustrate how to create an iOS application by Xcode
  • Watch a video illustrate how to create an iOS application by Xcode
  • How to develop an iOS application

    1. 1. How to develop an iOS application Objective-C – Xcode – iOS Le Thanh Quang Mobile tea April 19th 2012
    2. 2. Agenda Objective-C in brief Xcode iOS frameworks www.exoplatform.com - Copyright 2012 eXo Platform 2
    3. 3. Objective-Cwww.exoplatform.com - Copyright 2012 eXo Platform 3
    4. 4. Objective-C – What is it?Simple extension of the C languageAdds object-oriented capabilities to C language Runtime system (C library) Dynamic typing Dynamic bindingGCC/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. 5. Objective-C – Who use?Apple Inc.Mac OS X developers Cocoa framework Core animation, Core data, etciOS developers Cocoa touch framework Core animation, Core data, etc www.exoplatform.com - Copyright 2012 eXo Platform 5
    6. 6. Objective-C – Why should I (Java developer)care?Make up your mind with new code designsiPhone/iPad devices become popular rich user agents in enterprise marketeXo Platform 3.5, cloud-workspaces.com are integrated with iOS based devices and Android familyPlay around for fun or profit in free time ;) www.exoplatform.com - Copyright 2012 eXo Platform 6
    7. 7. Objective-C – History Appeared in 1983 Designed by Tom Love & Brad Fox Major implementations GCC, Clang Inf uenced by l Smalltalk, C OS Cross-platform www.exoplatform.com - Copyright 2012 eXo Platform 7
    8. 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. 9. Objective-C and Java Message SyntaxJava myString.toString()Objective-C * Square brackets for message expressions [myString description] www.exoplatform.com - Copyright 2012 eXo Platform 9
    10. 10. Objective-C and Java Method argumentsJava person.setFirstName(“Fred”)Objective-C * Arguments are delimited by colons [person setFirstName:@”Fred”] www.exoplatform.com - Copyright 2012 eXo Platform 10
    11. 11. Objective-C and Java Object Data typesJava 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. 12. Objective-C and Java Object Data typesJava * 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. 13. Objective-C and Java Prefix vs Package pathJava java.lang.String s = new String(“hello”);Objective-C * Objective-C doesnt 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. 14. Objective-C and Java Method prototypesJava 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. 15. Objective-C and Java Method prototypesObjective-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. 16. Objective-C and Java ClassJava ...Objective-C www.exoplatform.com - Copyright 2012 eXo Platform 16
    17. 17. Objective-C and Java Anatomy of Class Declaration www.exoplatform.com - Copyright 2012 eXo Platform 17
    18. 18. Objective-C Class Implementation www.exoplatform.com - Copyright 2012 eXo Platform 18
    19. 19. Objective-C and Java ClassJava ...Objective-C www.exoplatform.com - Copyright 2012 eXo Platform 19
    20. 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. 21. Objective-C – Memory management www.exoplatform.com - Copyright 2012 eXo Platform 21
    22. 22. Objective-C – Categories www.exoplatform.com - Copyright 2012 eXo Platform 22
    23. 23. Objective-C – Using category www.exoplatform.com - Copyright 2012 eXo Platform 23
    24. 24. Objective-C – BlocksA 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. 25. Objective-C – BlocksA 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] || ([valuedoubleValue] == stopValue)) { *stop = YES; stoppedEarly = YES; // ILLEGAL }}]; www.exoplatform.com - Copyright 2012 eXo Platform 25
    26. 26. Objective-C – BlocksWhen 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
    27. 27. Xcodewww.exoplatform.com - Copyright 2012 eXo Platform 27
    28. 28. XcodeIDE for iPhone projects Build Run (Simulator, device) Debug Source code management (SCM) Documentation www.exoplatform.com - Copyright 2012 eXo Platform 28
    29. 29. XcodeAutomatically maintain build scriptsDisplay logical grouping of files No package paths By default, groups not mapped to folder structureResources Automatically bundled with executableFrameworks Linked at compile time; no classpath needed www.exoplatform.com - Copyright 2012 eXo Platform 29
    30. 30. Xcode - Interface BuilderVisual GUI design toolDoesnt generate codeWorking 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. 31. Xcode DEMO www.exoplatform.com - Copyright 2012 eXo Platform 31
    32. 32. iOSwww.exoplatform.com - Copyright 2012 eXo Platform 32
    33. 33. iOS – Layered architectureC libraries and system callsCore services (C libraries and Objective-Cframeworks)Media Layer (C libraries and Objective-Cframeworks)Cocoa touch Foundation framework UIKit www.exoplatform.com - Copyright 2012 eXo Platform 33
    34. 34. iOS – Design Patterns MVC Pattern Delegate Pattern Target/Action Pattern www.exoplatform.com - Copyright 2012 eXo Platform 34
    35. 35. iOS – MVC Pattern Model View Controller www.exoplatform.com - Copyright 2012 eXo Platform 35
    36. 36. iOS – MVC PatternModel 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. 37. iOS – MVC PatternView 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. 38. iOS – MVC PatternController 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. 39. iOS – Delegation PatternControl passed to delegate objects to perform applicationspecific behaviorAvoids need to subclass complex objectsMany UIKit classes use delegates UIApplication UITableView UITextField www.exoplatform.com - Copyright 2012 eXo Platform 39
    40. 40. iOS – Target/Action Pattern When event occurs, action is invoked on targetobject Target: myObject sayHello Action: @selector(sayHello) Event: UIControlEventTouchUpInside Controller www.exoplatform.com - Copyright 2012 eXo Platform 40
    41. 41. ReferencesTraining for newcomer of Mobile team -http://int.exoplatform.org/portal/g/:spaces:mobile/mobile/local._wiki.WikiPortlet/group/spaces/mobile/iOS_TrainingJonathan Lehr -http://jonathanlehr.files.wordpress.com/2009/09/objective-c-and-java.pdfstanford.edu - http://www.stanford.edu/class/cs193p/cgi-bin/drupal/ www.exoplatform.com - Copyright 2012 eXo Platform 41
    42. 42. Questions?www.exoplatform.com - Copyright 2012 eXo Platform 42

    ×