이 글은 강의 중 do-it-swift 코드중 table view 실습 중 나온 코드를 하나하나 뜯어 보기 위한 글이다.
이 코드에 swift를 다루기 위한 코드의 집약체라고 들어서 뜯어보는 글이다.
//전체 코드
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath)
-> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "myCell", for: indexPath)
cell.textLabel?.text = items[(indexPath as NSIndexPath).row]
cell.imageView?.image = UIImage(named: itemsImageFile[(indexPath as NSIndexPath).row])
return cell
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
let cell = tableView.dequeueReusableCell(withIdentifier: "myCell", for: indexPath)
이로 인해 메모리 의 관리를 편하게 할 수 있게 된다.
cell.textLabel?.text = items[(indexPath as NSIndexPath).row]
cell.imageView?.image = UIImage(named: itemsImageFile[(indexPath as NSIndexPath).row])
옵셔널 체이닝 - 값이 존재할 때만 코드를 실행
ex) ?. 으로 표기 한다.
return cell
}
코드 : 이지스퍼블리싱 "do-it-swift"
참고 : chat gpt