lecture4
The Launch Cycle
When your app is launched (either into the foreground or background), use your app delegate’s application:willFinishLaunchingWithOptions:
and application:didFinishLaunchingWithOptions:
methods.
At launch time, the system automatically loads your app’s main storyboard file and loads the initial view controller. For apps that support state restoration, the state restoration machinery restores your interface to its previous state between calls to the application:willFinishLaunchingWithOptions:
and application:didFinishLaunchingWithOptions:
methods.
Slider
SliderLabel – displays the slider’s value on the label.
Slider2 – displays the slider‘s value on the textfield & sets the slider’s value by entering the textfield value.
LECTURE3
lecture3
Guide to Reference
ARC is a compile time feature that is Apple’s version of automated memory management. It stands for Automatic Reference Counting. This means that it only frees up memory for objects when there are zero strong references/ to them.
A guide to reference: when to use Strong reference, Weak reference, Unowned reference, ImplicitlyUnwrappedOptional property
|
Optional |
non-Optional |
Optional |
strong reference & weak reference |
strong reference & unowned reference |
non-Optional |
strong reference & unowned reference |
unowned reference & implicitly unwrapped optional property |
HW 2
“iOS application” survey
Fall 2015
Kyoung Shin Park
September 21, 2015
Individual assignment – “iOS Quantified Self Movement application” survey report (10 points 3 page)
The goal of this assignment is for you to learn the key design aspect of iPhone/iPad applications , and think about how to design if you would create your own iOS application.
In this assignment, you are to research 2~3 subjects of your interest on mobile applications from the web sites given below (or other sites) and then summit the report (3-page) on “iOS Quantified Self Movement Application”, due by Oct 5th, 2015.
Reference:
Quantified Self http://quantifiedself.com/guide/
Fitbit (Fitbit is a small device to track your physical activity or sleep. You can wear the device all day because it easily clips in your pocket, pants, shirt, bra, or to your wrist when you are sleeping.) http://fitbit.com/
Moodpanda (MoodPanda.com is a mood tracking website and iphone app. Tracking is very simple: you rate your happiness on a 0-10 scale, and optionally add a brief twitter-like comment on what’s influencing your mood.) http://moodpanda.com
Digifit (The Digifit ecosystem is a full suite of Apple apps that records heart rate, pace, speed, cadence, and power of your running, cycling and other athletic endeavors.) http://digifit.com/
Momento (Momento is an iPhone journal writing app. It allows you to make entries using text or photos and allows you to tag them with people from your address book, and locations from the GPS as well as category tags.)http://www.momentoapp.com
Foresquare (Foursquare is a service that helps you keep track of the places that you visit.) https://foursquare.com/
Extension
extension String {
func toFloat() -> Float {
if let unwrappedNum = Float(self) {
return unwrappedNum
}
else {
print(“Error converting \”” + self + “\” to Float”)
return 0.0
}
}
}
// Double to String with Format
var text = String.localizedStringWithFormat(“%.2f”, doubleValue)
// String to Float/Double
var floatValue = text.toFloat()
Value vs Reference Type
Understanding Value and Reference Types in Swift
http://alejandromp.com/blog/2014/8/30/understanding-value-and-reference-types-in-swift/
Enumeration, Class, Structure
// Enumeration & Class & Structure: Playground – noun: a place where people can play
// 2015.09.21 Kyoung Shin Park @ Dankook University
import Cocoa
func sayHello(personName: String = “World”) -> String {
let greeting = “Hello, ” + personName + “!”
return greeting
}
print(sayHello())
print(sayHello(“Anna”))
// Enumeration
enum Gender {
case Female
case Male
init() { // initialization
self = .Female
}
init(_ name: String)
{
switch name {
case “Female”, “여자”: self = .Female
case “Male”, “남자”: self = .Male
default: self = .Female
}
}
var description: String {
switch self {
case .Female: return “FEMALE~”
case .Male: return “MALE~”
}
}
}
var gender = Gender()
print(gender.description)
gender = Gender(“남자”)
print(gender.description)
gender = Gender.Female
gender = .Male
print(Gender.Male.description)
switch gender {
case .Female: print(“FEMALE!!”)
case .Male: print(“MALE!!”)
}
// Enum, multiple member values can appear on a single line, separated by commas
// Enum rawValue
enum Planet: Int {
case Mercury=1, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune
}
let earthID = Planet.Earth.rawValue
let somePlanet = Planet.Earth
switch somePlanet {
case .Earth:
print(“Mostly harmless”)
default:
print(“Not a safe place for humans”)
}
let aPlanet = Planet(rawValue: 7)
switch aPlanet! {
case .Earth:
print(“Mostly harmless”)
default:
print(“Not a safe place for humans”)
}
if let possiblePlanet = Planet(rawValue: 9) {
switch possiblePlanet {
case .Earth:
print(“Mostly harmless”)
default:
print(“Not a safe place for humans”)
}
} else {
print(“There isn’t a planet at position 9”)
}
// Enum associated values
enum TrainStatus {
case OnTime
case Delayed(Int)
}
var status:TrainStatus = .Delayed(5)
status = .OnTime
switch status {
case .OnTime:
print(“Train is on time”)
case .Delayed(let minutes):
print(“Train is delayed by \(minutes) minutes”)
}
// class
class Vehicle {
// stored properties
var numberOfPassengers: Int = 2
var numberOfWheels: Int = 4
// computed properties
var NumberOfWheels: Int {
get { return numberOfWheels }
set { numberOfWheels = newValue }
}
var description: String {
return “\(numberOfWheels) number of wheels”
}
}
class Bicycle: Vehicle {
override init() {
super.init()
numberOfPassengers = 1
numberOfWheels = 2
}
}
class Car: Vehicle {
// stored properties
var minVelocity: Int = 30
var accelVelocity: Int = 10
// computed properties
var speed: Int {
get {
return minVelocity + accelVelocity
}
set(newVelocity) {
accelVelocity = newVelocity – minVelocity
}
}
override init() {
super.init()
numberOfWheels = 5
}
override var description: String {
return “\(numberOfWheels) number of wheels with \(speed) speeds”
}
}
let aVehicle = Vehicle()
print(aVehicle.description)
aVehicle.numberOfWheels = 6
print(aVehicle.description)
let aBike = Bicycle()
print(aBike.description)
let aCar = Car()
print(aCar.description)
// structure
struct Frame {
var x: Int, y: Int // stored properties
var width: Int, height: Int // stored properties
var area: Int { // computed properties (getter)
return width * height
}
mutating func addWidth (width: Int) {
self.width += width // mutating modifies the value of a stored property in struct
}
}
let f = Frame(x:5, y:10, width:100, height:100)
print(f.width)
//f.width = 250 // invalid (due to let)
var g = Frame(x:5, y:10, width:100, height:100)
g.addWidth(15) // use mutating func to modify the value of a stored property in struct
print(g.width)
let h = Frame(x:5, y:10, width:100, height:100)
//h.addWidth(15) // compiler error (can’t call mutating func of struct stored in a let)
print(h.width)