import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
}
import UIKit
: 이 파일은 iOS 의 사용자 인터페이스 toolkit을 참조한다는 의미이다.
class ViewController: UIViewController
: UIViewController를 기반으로 ViewController라는 새로운 데이터 화면을 만들고 싶다는 의미이다.
override func viewDidLoad
: UIViewController의 viewDidLoad 메서드를 viewController에서 변경하고 싶다는 의미이다.
viewDidLoad 메서드에 포함된 super.viewDidLoad()
: 내가 viewDidLoad에 작성한 코드를 실행하기 전에 UIViewController의 viewDidLoad 코드를 실행하라는 의미이다.
let fm = FileManager.default
let path = Bundle.main.resourcePath!
let items = try! fm.contentsOfDirectory(atPath: path)
for item in items {
if item.hasPrefix("nssl") {
//this is a picture to load!
}
}
let fm = FileManager.default
: fm이라는 상수를 선언하고 FileManager.default에서 반환된 값을 할당한다. 이것은 우리가 파일시스템으로 작업할 수 잇게 해주는 데이터 유형이고 이 경우 파일을 찾는데 이것을 사용한다
let path = Bundle.main.resourcePath!
: path라는 상수를 선언하고 이는 우리 앱 번들의 리소스 경로이다. 번들은 컴파일된 우리 프로그램과 모든 asset을 포함하는 디렉토리이다. 따라서 이 줄은 "내가 앱에 추가한 이미지들을 어디서 찾을 수 있는지 말해라" 라는 의미이다.
let items = try! fm.contentsOfDirectory(atPath: path)
: item이라는 상수를 선언하고 이는 해당 path의 디렉토리의 내용이다.
if item.hasPrefix("nssl")
: 작업할 준비가 된 파일을 item이라 부르고 hasPrefix메서드를 사용하여 true 인 경우 코드 블럭을 실행한다.