Course material
|
Mobile landscape
iOS vs. Android
market share, ease of development, profits vs. volume, ...
iOS platform
iOS history: 2007 release, App Store, Xcode IDE, ...
iOS architecture: Cocoa Touch, media layer, core services, core OS
native vs. Web vs. bybrid development
Swift programming language
released in 2014 (replacing Objective-C)
variables
let vs. var
scope - can have variable shadowing (override variable in new scope)
data types (Int, Double, Boolean, Character, String, ...)
fully type safe, type inferencing
Optional types
used when value may or may not be present, e.g., Int(x) may return nil
unwrap using !, or if-let
optional type can be declared: String?, Int?, ...
expressions and operations
+, -, *, /, %, +=, -=, *=, /=, %= (no ++ or --)
==, !=, <, <=, >, >=
cannot have mixed types in an expression
Strings
+ operator, multiline strings using """, string comparison (==, >, ...)
fields: count
methods: lowercased, uppercased, contains, hasPrefix, hasSuffix, ...
can use string interpolation to embed values in a string (e.g., for printing)
control statements
if, if-else, while, for
specify ranges using ... or ..<
functions
internal vs. external names for parameters, default parameters
return type specified using ->
defining types
struct: generally used for data structures
fields (a.k.a. properties)
by default, fields are public
can specify private, inaccessible except through methods
can specify private(set) to make accessible, but not changeable
computed properties/fields act like methods but look like fields
methods:
init method serves same purpose as Java constructor
methods that change fields must be identified as mutating
structs do not support inheritance
implemented as value type - makes copy when assigned/passed
class: generally used when inheritance is needed (e.g., ViewController)
standard practice: private fields, init to construct
supports inheritance
must specify which methods override parent
use super. to call methods in parent class
implemented as reference type - assigns/passes reference to object
collections
Array
e.g., var names = ["Chris", "Pat"]
access via [], e.g., names[0]
fields: count
methods: append, +=, remove, insert
Dictionaries (maps)
e.g., var ages = ["Chris": 20, "Pat": 21]
access via []: ages["Chris"]
fields: count, keys
note: collections are structs, so value types
Xcode & iOS UIkit
Xcode IDE
playgrounds vs. projects
IDE areas: editor, toolbar, navigator, debug, utility
Interface Builder is integrated into the editor area
UIKit
code framework for building iOS apps
UIView is the foundational class for displaying things
subclasses: UILabel, UIImageView, UITextView, UIScrollView
UITableView, UIToolbar, UINavigationBar, UITabBar
UIControl defines control elements (subclass of UIView)
subclasses: UIButton, UISwitch, UISegmentedControl, UITextField,
UISlider, UIDatePicker, UIStepper
Stack View groups elements horizontally or vertically
useful for performing auto layout on a group of elements
Gesture Recognizers can specify actions for taps, swipes, shakes, ...
Model-View-Controller pattern
Model defines the logic of the app
usually defined in separate Swift structs/classes
View defines the interface for the app
created in Interface Builder, displayed as the StoryBoard
Controller conects the View interface with the Model logic
each View has its own ViewController
Common tasks
add a UI element: drag from object library onto storyboard
create an outlet: control-drag from UI element to ViewController
adds a fields associated with that UI element
create an action: control-drag from UI element to ViewController
adds a method associated with the specified action
app layout:
center elements using Add New Alignment Constraints
fix size and position relatively using Add New Constraints
group elements horzontally or vertically using stack views
app icon:
start with a square image, generate diff. resolutions (via Web site)
drag appropriately-sized images into template in Assets folder
|