스탠포드 iOS 강의노트 L1,2,3

Lecture 1 ~ 3

Lecture 1: Intro to iOS 10, Xcode 8, Swift 3

Lecture 2: MVC; iOS, Xcode and Swift Demonstration

Lecture 3: More Swift and the Foundation Framework

Course Description Updated for iOS 10 and Swift. Tools and APIs required to build applications for the iPhone and iPad platforms using the iOS SDK. User interface design for mobile devices and unique user interactions using multi-touch technologies. Object-oriented design using model-view-controller paradigm, memory management, Swift programming language. Other topics include: object-oriented database API, animation, mobile device power management, multi-threading, networking and performance considerations.

Mandatory Articles

Class: UIViewController

Arguments and Parameters




DIY. Make calculator

01. User Typing Digits

var isUserTyping: Bool = false
    
@IBAction func touchDigit(_ sender: UIButton) {
    let digit = sender.currentTitle!
    
    if isUserTyping {
        let textCurrentlyInDisplay = display!.text!
        display!.text = textCurrentlyInDisplay + digit
    }else {
        display!.text = digit
        isUserTyping = true
    }
}

02. Computed Properties

// Computed properties
var displayValue: Double {
    get {
        return Double(display!.text!)!
    }
    set {
        display?.text = String(newValue)
    }
}

03. Define Operating Action

@IBAction func operation(_ sender: UIButton) {
    isUserTyping = false
    if let mathSymbol = sender.currentTitle {
        switch mathSymbol {
        case "√" :
            displayValue = sqrt(displayValue)
        default :
            break
        }
    }
}

04. Divide Operation to Model

import Foundation
//  This is the Model of Calculator Brain.
//  UI Independent, Read - only.

struct CalculatorBrain {
    
    private var accumulator: Double
    
    func performOperation(_ symbol: String) {
  
    }
    
    func setOperand(_ operand: Double) {
      
    }
    
    // Computed properties
    var result: Double {
        get {
            
        }
    }
}

05. Operation Action과 Model 연결

private var brain: CalculatorBrain = CalculatorBrain()

@IBAction func performOperation(_ sender: UIButton) {
    if isUserTyping {
        brain.setOperand(displayValue)
        isUserTyping = false
    }
    
    if let mathSymbol = sender.currentTitle {
        brain.performOperation(mathSymbol)
    }
    
    if let result = brain.result {
        displayValue = result
    }
}
    

06. Model 기능 완성하기