Skip to content

Commit

Permalink
[#79] 프로토콜 사용해서 리터럴한 값 덜어내기, 상수값 관리하기
Browse files Browse the repository at this point in the history
  • Loading branch information
Taehyeon-Kim committed Aug 1, 2022
1 parent a3139d7 commit 56c7fe1
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 8 deletions.
16 changes: 16 additions & 0 deletions NetworkBasic/NetworkBasic.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
BD7E81462893888400E86383 /* Galmuri11.ttf in Resources */ = {isa = PBXBuildFile; fileRef = BD7E81432893888300E86383 /* Galmuri11.ttf */; };
BD7E81472893888400E86383 /* Galmuri7.ttf in Resources */ = {isa = PBXBuildFile; fileRef = BD7E81442893888300E86383 /* Galmuri7.ttf */; };
BD7E81482893888400E86383 /* Galmuri9.ttf in Resources */ = {isa = PBXBuildFile; fileRef = BD7E81452893888400E86383 /* Galmuri9.ttf */; };
BD857383289752C0007F294F /* ReusableViewProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD857382289752C0007F294F /* ReusableViewProtocol.swift */; };
BD85738628975827007F294F /* Constant.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD85738528975827007F294F /* Constant.swift */; };
BDB0926328920CCB00B0A4E1 /* ViewPresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDB0926228920CCB00B0A4E1 /* ViewPresentable.swift */; };
/* End PBXBuildFile section */

Expand All @@ -53,6 +55,8 @@
BD7E81432893888300E86383 /* Galmuri11.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = Galmuri11.ttf; sourceTree = "<group>"; };
BD7E81442893888300E86383 /* Galmuri7.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = Galmuri7.ttf; sourceTree = "<group>"; };
BD7E81452893888400E86383 /* Galmuri9.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = Galmuri9.ttf; sourceTree = "<group>"; };
BD857382289752C0007F294F /* ReusableViewProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReusableViewProtocol.swift; sourceTree = "<group>"; };
BD85738528975827007F294F /* Constant.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constant.swift; sourceTree = "<group>"; };
BDB0926228920CCB00B0A4E1 /* ViewPresentable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewPresentable.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -86,6 +90,7 @@
BD7915092890DDA8000A12EE /* NetworkBasic */ = {
isa = PBXGroup;
children = (
BD85738428975817007F294F /* Constant */,
BD7E813C289384A700E86383 /* Resource */,
BDB0926128920CAF00B0A4E1 /* SearchScene */,
BDB0926028920CA200B0A4E1 /* Protocol */,
Expand Down Expand Up @@ -118,10 +123,19 @@
path = Resource;
sourceTree = "<group>";
};
BD85738428975817007F294F /* Constant */ = {
isa = PBXGroup;
children = (
BD85738528975827007F294F /* Constant.swift */,
);
path = Constant;
sourceTree = "<group>";
};
BDB0926028920CA200B0A4E1 /* Protocol */ = {
isa = PBXGroup;
children = (
BDB0926228920CCB00B0A4E1 /* ViewPresentable.swift */,
BD857382289752C0007F294F /* ReusableViewProtocol.swift */,
);
path = Protocol;
sourceTree = "<group>";
Expand Down Expand Up @@ -219,9 +233,11 @@
BD79150F2890DDA8000A12EE /* ViewController.swift in Sources */,
BD79150B2890DDA8000A12EE /* AppDelegate.swift in Sources */,
BD4566EC2892239F009B4514 /* LottoViewController.swift in Sources */,
BD857383289752C0007F294F /* ReusableViewProtocol.swift in Sources */,
BD7E813B28935E1600E86383 /* LocationViewController.swift in Sources */,
BD4566F228923DFA009B4514 /* Utils.swift in Sources */,
BD79151F2890E249000A12EE /* SearchViewController.swift in Sources */,
BD85738628975827007F294F /* Constant.swift in Sources */,
BD4566EE28923052009B4514 /* TranslateViewController.swift in Sources */,
BD79150D2890DDA8000A12EE /* SceneDelegate.swift in Sources */,
BD7915222890E4EB000A12EE /* ListTableViewCell.swift in Sources */,
Expand Down
37 changes: 37 additions & 0 deletions NetworkBasic/NetworkBasic/Constant/Constant.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// Constant.swift
// NetworkBasic
//
// Created by taekki on 2022/08/01.
//

import Foundation

//enum StoryboardName: String {
// case Main
// case Search
// case Setting
//}

struct StoryboardName {

// 접근 제어를 통해 초기화 방지
private init() {}

static let main = "Main"
static let search = "Search"
static let setting = "Setting"
}

/*
1. struct type property vs enum type property => 인스턴스 생성 방지(열거형은 초기화 x)
2. enum case vs enum static => 중복된 내용을 하드 코딩할 수 있나, case에는 제약이 존재(UIColor, UIImage 사용 x)
*/
//enum StoryboardName {
//// var nickname = "고래밥" // 인스턴스를 만들지 못하기 때문에 저장 프로퍼티 사용 불가
//
// // 타입 프로퍼티 사용 가능
// static let main = "Main"
// static let search = "Search"
// static let setting = "Setting"
//}
1 change: 0 additions & 1 deletion NetworkBasic/NetworkBasic/LocationViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import UIKit

class LocationViewController: UIViewController {

// Notification 1. 인스턴스 생성
let notificationCenter = UNUserNotificationCenter.current()

Expand Down
26 changes: 26 additions & 0 deletions NetworkBasic/NetworkBasic/Protocol/ReusableViewProtocol.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// ReusableViewProtocol.swift
// NetworkBasic
//
// Created by taekki on 2022/08/01.
//

import UIKit

protocol ReusableViewProtocol: AnyObject {
static var reuseidentifier: String { get }
}

extension UIViewController: ReusableViewProtocol {
// 연산 프로퍼티의 형태로 나옴.
// 연산 프로퍼티 get만 사용한다면 get 생략 가능.
static var reuseidentifier: String {
return String(describing: self)
}
}

extension UITableViewCell: ReusableViewProtocol {
static var reuseidentifier: String {
return String(describing: self)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@

import UIKit

class ListTableViewCell: UITableViewCell {

static let identifier = "ListTableViewCell"

class ListTableViewCell: UITableViewCell {
@IBOutlet weak var titleLabel: UILabel!
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ class SearchViewController: UIViewController, UITableViewDelegate, UITableViewDa
// 테이블 뷰가 사용할 테이블뷰 셀(XIB) 등록
// XIB: xml interface builder <= NIB
// Literal한 문자열은 제거하자
searchTableView.register(UINib(nibName: ListTableViewCell.identifier, bundle: nil), forCellReuseIdentifier: ListTableViewCell.identifier)
searchTableView.register(UINib(nibName: ListTableViewCell.reuseidentifier, bundle: nil), forCellReuseIdentifier: ListTableViewCell.reuseidentifier)
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 100
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: ListTableViewCell.identifier, for: indexPath) as? ListTableViewCell else {
guard let cell = tableView.dequeueReusableCell(withIdentifier: ListTableViewCell.reuseidentifier, for: indexPath) as? ListTableViewCell else {
return UITableViewCell()
}

Expand Down
3 changes: 2 additions & 1 deletion NetworkBasic/NetworkBasic/WebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import UIKit
import WebKit

class WebViewController: UIViewController {

// WebViewController.self 메타 타입 => "WebViewController"

@IBOutlet weak var searchBar: UISearchBar!
@IBOutlet weak var webView: WKWebView!

Expand Down

0 comments on commit 56c7fe1

Please sign in to comment.