Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 51 additions & 2 deletions iOS_Study_B.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
954B6B882AC57DAA00FDCFAB /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 954B6B862AC57DAA00FDCFAB /* Main.storyboard */; };
954B6B8A2AC57DAB00FDCFAB /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 954B6B892AC57DAB00FDCFAB /* Assets.xcassets */; };
954B6B8D2AC57DAB00FDCFAB /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 954B6B8B2AC57DAB00FDCFAB /* LaunchScreen.storyboard */; };
CC3EE7BB2B073A56009C5287 /* MemoDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC3EE7BA2B073A56009C5287 /* MemoDetailViewController.swift */; };
CC3EE7BD2B073DF9009C5287 /* MemoEditViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC3EE7BC2B073DF9009C5287 /* MemoEditViewController.swift */; };
CC7D36DA2B04DA780069F109 /* SnapKit in Frameworks */ = {isa = PBXBuildFile; productRef = CC7D36D92B04DA780069F109 /* SnapKit */; };
CC7D36DC2B04DA780069F109 /* SnapKit-Dynamic in Frameworks */ = {isa = PBXBuildFile; productRef = CC7D36DB2B04DA780069F109 /* SnapKit-Dynamic */; };
CC7D36DE2B04E1380069F109 /* MemoTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC7D36DD2B04E1380069F109 /* MemoTableViewCell.swift */; };
CC7D36E42B05A0D60069F109 /* MemoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC7D36E32B05A0D60069F109 /* MemoViewController.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -24,13 +30,19 @@
954B6B892AC57DAB00FDCFAB /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
954B6B8C2AC57DAB00FDCFAB /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
954B6B8E2AC57DAB00FDCFAB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
CC3EE7BA2B073A56009C5287 /* MemoDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MemoDetailViewController.swift; sourceTree = "<group>"; };
CC3EE7BC2B073DF9009C5287 /* MemoEditViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MemoEditViewController.swift; sourceTree = "<group>"; };
CC7D36DD2B04E1380069F109 /* MemoTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MemoTableViewCell.swift; sourceTree = "<group>"; };
CC7D36E32B05A0D60069F109 /* MemoViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MemoViewController.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
954B6B7A2AC57DAA00FDCFAB /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
CC7D36DA2B04DA780069F109 /* SnapKit in Frameworks */,
CC7D36DC2B04DA780069F109 /* SnapKit-Dynamic in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -56,13 +68,17 @@
954B6B7F2AC57DAA00FDCFAB /* iOS_Study_B */ = {
isa = PBXGroup;
children = (
CC7D36DD2B04E1380069F109 /* MemoTableViewCell.swift */,
954B6B802AC57DAA00FDCFAB /* AppDelegate.swift */,
954B6B822AC57DAA00FDCFAB /* SceneDelegate.swift */,
954B6B842AC57DAA00FDCFAB /* ViewController.swift */,
CC7D36E32B05A0D60069F109 /* MemoViewController.swift */,
954B6B862AC57DAA00FDCFAB /* Main.storyboard */,
954B6B892AC57DAB00FDCFAB /* Assets.xcassets */,
954B6B8B2AC57DAB00FDCFAB /* LaunchScreen.storyboard */,
954B6B8E2AC57DAB00FDCFAB /* Info.plist */,
CC3EE7BA2B073A56009C5287 /* MemoDetailViewController.swift */,
CC3EE7BC2B073DF9009C5287 /* MemoEditViewController.swift */,
);
path = iOS_Study_B;
sourceTree = "<group>";
Expand All @@ -83,6 +99,10 @@
dependencies = (
);
name = iOS_Study_B;
packageProductDependencies = (
CC7D36D92B04DA780069F109 /* SnapKit */,
CC7D36DB2B04DA780069F109 /* SnapKit-Dynamic */,
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

스냅킷 추가하실 때 SnapKit-Dynamic말고 SnapKit 하나만 추가해주세요!

productName = iOS_Study_B;
productReference = 954B6B7D2AC57DAA00FDCFAB /* iOS_Study_B.app */;
productType = "com.apple.product-type.application";
Expand Down Expand Up @@ -111,6 +131,9 @@
Base,
);
mainGroup = 954B6B742AC57DAA00FDCFAB;
packageReferences = (
CC7D36D82B04DA780069F109 /* XCRemoteSwiftPackageReference "SnapKit" */,
);
productRefGroup = 954B6B7E2AC57DAA00FDCFAB /* Products */;
projectDirPath = "";
projectRoot = "";
Expand Down Expand Up @@ -139,8 +162,12 @@
buildActionMask = 2147483647;
files = (
954B6B852AC57DAA00FDCFAB /* ViewController.swift in Sources */,
CC3EE7BB2B073A56009C5287 /* MemoDetailViewController.swift in Sources */,
954B6B812AC57DAA00FDCFAB /* AppDelegate.swift in Sources */,
CC7D36E42B05A0D60069F109 /* MemoViewController.swift in Sources */,
954B6B832AC57DAA00FDCFAB /* SceneDelegate.swift in Sources */,
CC7D36DE2B04E1380069F109 /* MemoTableViewCell.swift in Sources */,
CC3EE7BD2B073DF9009C5287 /* MemoEditViewController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -291,7 +318,6 @@
INFOPLIST_FILE = iOS_Study_B/Info.plist;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
INFOPLIST_KEY_UIMainStoryboardFile = Main;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
LD_RUNPATH_SEARCH_PATHS = (
Expand All @@ -318,7 +344,6 @@
INFOPLIST_FILE = iOS_Study_B/Info.plist;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
INFOPLIST_KEY_UIMainStoryboardFile = Main;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
LD_RUNPATH_SEARCH_PATHS = (
Expand Down Expand Up @@ -356,6 +381,30 @@
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
CC7D36D82B04DA780069F109 /* XCRemoteSwiftPackageReference "SnapKit" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/SnapKit/SnapKit.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 5.6.0;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
CC7D36D92B04DA780069F109 /* SnapKit */ = {
isa = XCSwiftPackageProductDependency;
package = CC7D36D82B04DA780069F109 /* XCRemoteSwiftPackageReference "SnapKit" */;
productName = SnapKit;
};
CC7D36DB2B04DA780069F109 /* SnapKit-Dynamic */ = {
isa = XCSwiftPackageProductDependency;
package = CC7D36D82B04DA780069F109 /* XCRemoteSwiftPackageReference "SnapKit" */;
productName = "SnapKit-Dynamic";
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = 954B6B752AC57DAA00FDCFAB /* Project object */;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

119 changes: 119 additions & 0 deletions iOS_Study_B/MemoDetailViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
//
// MemoDetailViewController.swift
// iOS_Study_B
//
// Created by 임아영 on 11/17/23.
//

protocol MemoDetailDelegate: AnyObject {
func didUpdateDetailMemo(_ memo: Memo, atIndex index: Int)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

backButtonTapped 함수에서 값을 이미 넘겨주기 때문에 이 delegate는 필요없을 것 같아요!


protocol MemoEditDelegate: AnyObject {
func didUpdateMemo(_ memo: Memo, atIndex: Int)
}

extension MemoDetailViewController: MemoEditDelegate {
func didUpdateMemo(_ memo: Memo, atIndex: Int) {
displayMemo(memo)
}
}


import UIKit
import SnapKit

class MemoDetailViewController: UIViewController {

var memo: Memo?
var index: Int?
weak var delegate: MemoEditDelegate?
weak var detailDelegate: MemoDetailDelegate?


let Label1: UILabel = {
let label = UILabel()
label.font = UIFont.boldSystemFont(ofSize: 18)
return label
}()

let Label2: UILabel = {
let label = UILabel()
label.font = UIFont.systemFont(ofSize: 16)
label.numberOfLines = 0
return label
}()

override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white

navigationItem.title = "메모 상세"

configureSubviews()
makeConstraints()
setNavigationBar()

if let memo = memo {
displayMemo(memo)
}
}

func configureSubviews() {
view.addSubview(Label1)
view.addSubview(Label2)

}

func makeConstraints() {
Label1.snp.makeConstraints { make in
make.top.equalTo(view.safeAreaLayoutGuide.snp.top).offset(20)
make.leading.equalTo(view.safeAreaLayoutGuide.snp.leading).offset(20)
make.trailing.equalTo(view.safeAreaLayoutGuide.snp.trailing).offset(-20)
Comment on lines +63 to +64
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make.leading.trailing.equalTo(view.safeAreaLayoutGuide.snp.leading).inset(20) 한 줄로 가능합니다

}
Label2.snp.makeConstraints { make in
make.top.equalTo(Label1.snp.bottom).offset(20)
make.leading.equalTo(view.safeAreaLayoutGuide.snp.leading).offset(20)
make.trailing.equalTo(view.safeAreaLayoutGuide.snp.trailing).offset(-20)
}
}

func setNavigationBar() {
let editButton = UIBarButtonItem(title: "수정하기", style: .plain, target: self, action: #selector(editButtonTapped))
navigationItem.rightBarButtonItem = editButton
}

@objc func editButtonTapped() {
let MemoEditViewController = MemoEditViewController()

MemoEditViewController.memo = memo
MemoEditViewController.index = index
MemoEditViewController.delegate = self
self.navigationController?.pushViewController(MemoEditViewController, animated: true)
}

@objc func backButtonTapped() {
guard let updatedMemo = createUpdatedMemo() else {
return
}

detailDelegate?.didUpdateDetailMemo(updatedMemo, atIndex: index!)
self.navigationController?.popViewController(animated: true)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 함수를 만들고 호출 안 해주고 있어서 데이터 전달에 문제가 있는 것 같아요

delegate는 MemoEditDelegate 사용하도록 수정해주세요!


func createUpdatedMemo() -> Memo? {
guard let updatedTitle = Label1.text,
let updatedContent = Label2.text else {
return nil
}

return Memo(id: memo?.id, title: updatedTitle, content: updatedContent)
}

func displayMemo(_ memo: Memo) {
Label1.text = memo.title
Label2.text = memo.content
}
}


102 changes: 102 additions & 0 deletions iOS_Study_B/MemoEditViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
//
// MemoEditViewController.swift
// iOS_Study_B
//
// Created by 임아영 on 11/17/23.
//


import UIKit
import SnapKit


class MemoEditViewController: UIViewController {

var memo: Memo?
var index: Int?
weak var delegate: MemoEditDelegate?

let textfield: UITextField = {
let textfield = UITextField()
textfield.font = UIFont.systemFont(ofSize: 20)
textfield.keyboardType = .default
textfield.layer.cornerRadius = 5.0
textfield.layer.borderColor = UIColor.black.cgColor
textfield.layer.borderWidth = 1.0

return textfield
}()

let textfield2: UITextField = {
let textfield2 = UITextField()
textfield2.font = UIFont.systemFont(ofSize: 20)
textfield2.keyboardType = .default
textfield2.layer.cornerRadius = 5.0
textfield2.layer.borderColor = UIColor.black.cgColor
textfield2.layer.borderWidth = 1.0

return textfield2
}()

override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
navigationItem.title = "메모 수정"

configureSubviews()
makeConstraints()
setNavigationBar()

if let memo = memo {
displayMemo(memo)
}
}

func configureSubviews() {
view.addSubview(textfield)
view.addSubview(textfield2)
}

func makeConstraints() {
textfield.snp.makeConstraints { make in
make.height.equalTo(40.0)
make.top.equalTo(view.safeAreaLayoutGuide).inset(10)
make.leading.trailing.equalTo(view.safeAreaLayoutGuide).inset(18)
}
textfield2.snp.makeConstraints { make in
make.height.equalTo(40.0)
make.top.equalTo(view.safeAreaLayoutGuide).inset(60)
make.leading.trailing.equalTo(view.safeAreaLayoutGuide).inset(18)
}
}

func setNavigationBar() {
let setButton = UIBarButtonItem(title: "완료", style: .plain, target: self, action: #selector(setButtonTapped))
navigationItem.rightBarButtonItem = setButton
}

@objc func setButtonTapped() {
guard let updatedMemo = createUpdatedMemo(),
let delegate = delegate,
let index = index else {
return
}
delegate.didUpdateMemo(updatedMemo, atIndex: index)
self.navigationController?.popViewController(animated: true)
}

func displayMemo(_ memo: Memo) {
textfield.text = memo.title
textfield2.text = memo.content
}

func createUpdatedMemo() -> Memo? {
guard let updatedTitle = textfield.text,
let updatedContent = textfield2.text else {
return nil
}

return Memo(id: memo?.id, title: updatedTitle, content: updatedContent)
}
}

Loading