Skip to content

10 - iOS Intro

Requirements

  • Programming experience – java, databases, algorithms
  • OOP
    • Class, Instance, Superclass/Subclass
    • Message, Method
    • Protocol (interface)
    • Reference vs Value types, Instance variable
  • Functional programming – Closures/Delegates...


  • Latest Xcode (12.X-13.X-14.X-15.X)
  • IT College class 320
    • 13 M1 based iMac computers
  • Or macOS based computer (ca be rented from Apple resellers)
  • Or virtualized macOS (slow, but works)
  • Or rented virtual access
    • http://www.macincloud.com/ (~$10-20 month)
    • HostMyApple, MacStadium, vmOSX, Xcloud, Xcodeclub, …

Remote access to ICO-320

VPN - FortiClient VPN - https://www.fortinet.com/support/product-downloads#vpn


  • Server: portal.itcollege.ee
  • Port: 10443
  • User-Pass: uni-id and password
    • uni-id without any email part (drop the @ttu.ee or @taltech.ee)


Use VNC to access mac class


  • Teacher: 192.168.8.13
  • Students: 192.168.8.1 - 192.168.8.12


  • Vnc user: student
  • Vnc pass: student
  • Computer pass/user: uni-id and pass

IOS

iOS - overview

What’s in iOS – ~100% OOP

  • Core OS – close to hardware, everything in C
    • OSX Kernel, Mach 3, BSD, Sockets, Security, Power Management, Keychain Access, Certificates, File System, Bonjour
  • Core Services – OOP in top of hardware
    • Collections, Address Book, Networking, File Access, SQLite, Core Location, Net Services, Threading, Preferences, URL Utilities
  • Media – originally it was iPod
    • Core Audio, OpenAL, Audio Mixing, Audio Recording, Video Playback, Images, PDF, Quartz, Core Animation, OpenGL ES
  • Cocoa Touch – UI layer
    • Multi-Touch, Core Motion, View Hierarchy, Localization, Controls, Alerts, WebView, Map Kit, Image Picker, Camera

Swift language

  • Latest language in development scene (released in autumn 2014)
  • Current version is 5.X (5.9 with Xcode 15.0.1)
  • You can mix it with older Apple language of choice – Objective C (don't)
  • Language is open source
  • Can be used in other environments also (servers) – Kitura by IBM, Vapor, Perfect. Swift is used in ML (Tensorflow)


Mandatory reading – a Swift tour

MVC

  • All iOS development is MVC based!
    • Model – data and business logic
    • View – UI
    • Controller – the glue between View and Model
  • Controller can directly control Model and View (Outlet)
  • Model and View never communicate with each other
  • View communicates with controller via
    • Action
    • Outlet
    • Delegate (should, will, did) – property in view using protocol
    • Data source – protocol
  • Model communicates via broadcasts – notifications & KVO – Key Value Observing

XCode

IOS

IOS

IOS

  • Toolbar on top
  • Left - Navigation
  • Middle - Editor
  • Right - Utility

XCode storyboard

  • Open up Main.storyboard – UI editor
  • Click icon in upper right corner – PLUS or circle with square in it
  • Drag UI components to screen

IOS

Connecting UI and code

  • Open up side-by-side editor
    • click on

IOS
IOS

  • Open storyboard on one side and
  • Hold ctrl key and drag with your mouse from UI element to code
  • Choose type for connection: Outlet or Action
    • Action – UI calls into code (buttons)
    • Outlet – code updates UI (labels)
    • Outlet collection – array of UI elements

IOS

IOS

Hide touch keyboard

1
2
3
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        view.endEditing(true)
}

Home reading

https://docs.swift.org/swift-book/LanguageGuide/TheBasics.html
https://swift.org/documentation/api-design-guidelines/

  • Basics
    • Type Safety and Type Inference, Numeric Type Conversion, Optionals
  • Operators
    • Nil-Coalescing Operator, Range Operators
  • Strings and Characters
    • Counting Characters, Accessing and Modifying a String, Substrings
  • Collection Types
    • Mutability of Collections, Arrays, Dictionaries
  • Control flow
    • Switch, No Implicit Fallthrough, Break
  • Functions
    • Function Argument Labels and Parameter Names, Specifying Argument Labels
  • Classes and Structures
    • Structures and Enumerations Are Value Types
  • Properties
    • Type Properties
  • Methods
    • Type Methods
  • Inheritance
    • Overriding Methods
  • Initialization
    • Customizing Initialization