iOS Beginners Lesson 1

436 views
356 views

Published on

Fundamentals for programmers new to iOS development with Objective-C

Published in: Software
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

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

No notes for slide

iOS Beginners Lesson 1

  1. 1. INTRODUCTION to iOS Programming
  2. 2. ME • Travel & outdoor sports • Chemical engineering • Freezer engineering • Software consultant, technology businesses • Optometry & Real Estate
  3. 3. ME • http://calvinx.com • Twitter @calvinchengx • FB http://facebook.com/calvin.cheng.lc • Github http://github.com/calvinchengx
  4. 4. YOU?
  5. 5. WHY? • Why do we learn programming? • Why do you want to learn programming? • What problems do you want to solve? • Who can we help?
  6. 6. OVERVIEW • Lesson 1: Introductions • Lesson 2: iOS specifics • Lesson 3: Data Model • Lesson 4: Logic (Controller) & Interface
  7. 7. LESSON 1: INTRODUCTIONS • Hour 1 - Demo and Set-up • Hour 2 - Objective-C Primer • Hour 3 - MVC Architecture
  8. 8. DEMO
  9. 9. APPLE DEVELOPER
  10. 10. PREREQUISITES • Do you know an existing programming language or scripting language? • Control logic, data and interfaces - what do you want the user to see and/or do? • Objective-Oriented Programming?
  11. 11. COMPARISONS
  12. 12. OBJECT-ORIENTED PROGRAMMING • Class • Objects • Functions • Methods
  13. 13. KNOW A PROGRAMMING LANGUAGE? • C • Java? • Javascript? • Python? • Ruby?
  14. 14. C-STYLE LANGUAGES • C • C++ • Objective-C as a superset of C • PHP • C# • Java • Perl
  15. 15. OBJECTIVE-C SYNTAX • @ is used to identify Objective-C • Special keywords, e.g. protocol, property, interface, implementation, NSObject, NSInteger, NSNumber etc • Tokens, e.g. @, (, ; etc
  16. 16. XCODE: CREATE PROJECT
  17. 17. XCODE: CREATE PROJECT
  18. 18. OBJECTIVE-C PRIMER
  19. 19. • Basic Syntax • Variables and Data Types • Working with Objects • Classes and Objects • Collections • Files • Language Features • Errors and Debugging
  20. 20. BASIC SYNTAX • Objective-C is a superset of C programming language • i.e. it understands all C syntax • AND it introduces new syntax of its own on top of C
  21. 21. BASIC SYNTAX
  22. 22. BASIC SYNTAX
  23. 23. BASIC SYNTAX Code is grouped into “pairs” of: • Header file • Implementation file
  24. 24. BASIC SYNTAX
  25. 25. BASIC SYNTAX
  26. 26. BASIC SYNTAX
  27. 27. VARIABLES & DATA TYPE myemail@domain.com #ffffff 37 2008-08-08
  28. 28. VARIABLES & DATA TYPE myemail@domain.com #ffffff 37 2008-08-08 email: color: age: date of event:
  29. 29. VARIABLES & DATA TYPE Javascript var a = “wonderful”; a = 123; a = 1.289; a = false;
  30. 30. VARIABLES & DATA TYPE Objective-C type variable value int homeworkScore = 87;
  31. 31. VARIABLE & DATA TYPE Naming convention: camel case firstName score playerKarma my8Number NOT RECOMMENDED int_score NOT RECOMMENDED
  32. 32. VARIABLES & DATA TYPE Primitive Data Types int float double char BOOL Objective-C
  33. 33. VARIABLES & DATA TYPE Composite Data Types int day = 28; int month = 11; int year = 2011; int secondsSince1970 = 1294909373; char c1 = ‘h’; char c2 = ‘e’; char c3 = ‘l’; char c4 = ‘l’; char c5 = ‘o’;
  34. 34. VARIABLES & DATA TYPE Complex Types: iOS SDK (CocoaTouch Framework) NSString *myString = @“Hello”; NSDate *today = [NSDate date];
  35. 35. WORKING WITH OBJECTS Procedural Program (Example C program)
  36. 36. WORKING WITH OBJECTS Object Oriented Programs (Objective-C) data logic data logic data logic
  37. 37. WORKING WITH OBJECTS class object
  38. 38. CLASS = OBJECT BLUEPRINT
  39. 39. CLASS = OBJECT BLUEPRINT NSDate *today = [NSDate date]; ref - https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Cl asses/NSDate_Class/Reference/Reference.html
  40. 40. CLASS = OBJECT BLUEPRINT NSDate *today = [NSDate date]; ref - https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Cl asses/NSDate_Class/Reference/Reference.html What’s this?
  41. 41. CLASS = OBJECT BLUEPRINT • Pointers! • All objects are accessed using Pointers • * represents a pointer and a primitive value
  42. 42. USING OBJECTS
  43. 43. CLASS = OBJECT BLUEPRINT NSDate *today = [NSDate date]; ref - https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Cl asses/NSDate_Class/Reference/Reference.html What’s this?
  44. 44. METHODS NSDate *today = [NSDate date]; ref - https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Cl asses/NSDate_Class/Reference/Reference.html MethodClassType Pointer denotes that this variable is a Pointer
  45. 45. METHODS • Class Methods • Instance Methods (also known as Object Methods)
  46. 46. METHODS NSDate *today = [NSDate date] NSTimeInterval timeInterval = 123; NSDate *dateFromInterval = [NSDate dateWithTimeInterval:timeInterval sinceDate:today] Class Method
  47. 47. METHODS NSComparsionResult result = [today compare:dateFromInterval] Instance Method a.k.a. Object Method NSDate object from previous slide NSDate object from previous slide
  48. 48. COLLECTIONS • A group of data or objects • Various languages refer to them as “arrays” or “lists” or “dictionaries” or “linked lists” (each with slightly different underlying meaning)
  49. 49. COLLECTIONS
  50. 50. FILES
  51. 51. FILES • All programming languages provide a way to write to your computer’s/operating system’s filesystem • If we cannot put things into a file, the data that we are working with will not be available when our computer is switched off since it’s only in the memory
  52. 52. FILES
  53. 53. LANGUAGE FEATURES • Inheritance (e.g. NSObject > NSResponder > NSView > NSControl > NSButton) • Categories: extending a class with new methods without sub-classing
  54. 54. LANGUAGE FEATURES • Class Extensions: extending a class with new properties without sub-classing (only “.h” created, no implementation file :-))
  55. 55. LANGUAGE FEATURES • Categories versus Class Extensions
  56. 56. LANGUAGE FEATURES • Protocols: a list of methods you want a object to perform • required methods • optional methods • ANY object can perform those methods • Think of it as a set/group of methods (“functions”)
  57. 57. LANGUAGE FEATURES • Dynamic Typing with id • id is a generic object pointer
  58. 58. ERRORS & DEBUGGING • Issue navigator • Pick the first error (don’t start at the bottom) • Common errors: • Missing pointer symbol • Missing semi-colons or braces (parsing error) • Undeclared identifier (didn’t import a header?) • Learning to use breakpoints
  59. 59. MVC ARCHITECTURE • What is MVC? • Using the iOS Simulator in Xcode • Exercise Files • Features of our Note Taking App
  60. 60. WHAT IS MVC? • Model • View • Controller
  61. 61. WHAT IS MVC? Model • Representation of your class (“blueprint”, .h, .m) • Set properties and behaviour of your class • Set properties and behaviour of your class’ objects • Handles data storage in memory • Handles data storage on disk • Handles data storage to the “cloud”/backend
  62. 62. WHAT IS MVC? View • The interface for the user of your app - “Scene”, “Storyboard” • Listens to user interactions - tap, swipe, other events (shaking your phone) • Shows the user responses and ask for user responses • Aesthetic purpose as well as User function purpose • Usually tied to the logic (i.e. “controller”)
  63. 63. WHAT IS MVC? Controller • “ViewController” (.h, .m) • Your app should be organised with multiple ViewControllers with different purposes • Calls out classes, class methods, objects, object methods from your models, changes data according to user interactions and accepts or pushes data to the view • Using linked to scenes and UI (User Interface) object(s) on a scene
  64. 64. WHY MVC? • Organised, modular (cleanly separated code for easy debugging) • A convention for teamwork so others can easily get the “big picture” of the components that make your app work
  65. 65. IOS SIMULATOR
  66. 66. EXERCISE FILES • Github url
  67. 67. FEATURES OF OUR NOTE TAKING APP • Show list of notes • Create a note and be able to persist the note (“save”) • Edit a note • Delete a note
  68. 68. WHAT’S NEXT? • Lesson 1: Introductions • Lesson 2: iOS specifics • Lesson 3: Data Model • Lesson 4: Logic (Controller) & Interface

×