Lecture 1: Course Logistics and Introduction to SwiftUI

인생노잼시기·2021년 2월 19일
0

🏛Stanford

목록 보기
1/2

유튜브에서 Stanford CS193p iPhone Application Development Spring 2020을 들으며 기록했습니다.

Xcode12에서 실습

Welcome

What is this course about

Developing applications for iOS Using SwiftUI(iOS 13부터 시작)

  • user interface paradigm
    reactive(MVVM)
    declarative(imperative)

Card Matching Game

iOS > App(구 Single View app)

Life Cycle: SwiftUI App, UIKit App delegate 중 전자를 선택해서 생성했는데 후자를 선택했어야 하나보다
Interface: SwiftUI(UIKit) / Storyboard(구버전)
SwiftUI는 storyboard의 모든 내용을 커버할 수 없다

Finder 상단 메뉴 > 환경설정 > 사이드바 > home directory > Developer

behavior specification 함수형

  • SwiftUI(패키지) depends on Foundation
    SwiftUI를 import하는 것은 Foundation이 이미 import되어 있는 것과 같다

  • ContentView behaves like a View

  • ContentView는 화면 전체 크기

  • View는 그 안의 작은 네모

  • strut, class 안에 있는 var변수는 property라고 부른다

  • some View: 데이터 타입, View처럼 행동하는 아무거나

  • var body는 메모리에 저장되는 게 아니라 (not stored) 실행된다(execute)

  • Text()를 return한다 (return은 추론infer가능해서 생략가능하다)

  • view combiner로 연결하기 위해 some View라는 타입을 사용한다
    사용한 view combiner는 ZStack

  • body 안에 Text만 있을 때
    Text is View라서 some View 대신 Text를 써도 된다

  • HStack은 spacing을 설정하면 간격을 뗄 수 있는데
    padding도 그렇고 spacing도 그렇고 기본값을 사용하는 게 일반적이다

//
//  ContentView.swift
//  Memorize
//
//  Created by User on 2021/02/19.
//


import SwiftUI


struct ContentView: View {
    var body: some View {
        return HStack() {
            ForEach(0..<4){ index in
                CardView()
            }
        }
        
            .foregroundColor(Color.orange)
            .padding()
            .font(Font.largeTitle)
    }
}

struct CardView: View {
    var isFaceUp: Bool = true
    
    var body: some View {
        ZStack {
            if isFaceUp {
                RoundedRectangle(cornerRadius: 10.0).fill(Color.white)
                RoundedRectangle(cornerRadius: 10.0).stroke(lineWidth: 3)
                Text("👻")
            } else {
                RoundedRectangle(cornerRadius: 10.0).fill()
            }
        }
    }
}



struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
  • swift function call의 예시
    stroke <-> filling
    fill은 화면을 채우고
    stroke는 그 반대이다
    stroke()는 View를 리턴한다

    • stroke(lineWidth: 3) 선의 굵기
  • 오버라이딩
    만약 ZStack의 밖에 foregroundColor(Color.orange)라고 하고
    내부에서 foregroundColor(Color.blue)라고 한다

profile
인생노잼

1개의 댓글

comment-user-thumbnail
2021년 2월 19일

22분

답글 달기