memo 앱 만들기 (취소 기능)
import UIKit
class ComposeViewController: UIViewController {
@IBOutlet weak var memoTextView: UITextView!
@IBAction func close(_ sender: Any) {
//animated: true -> 전환 애니메이션 실행
//completion: function() -> 화면전환후 실행할 코드
dismiss(animated: true, completion: nil)
}
@IBAction func save(_ sender: Any) {
guard let memo = memoTextView.text,
memo.count > 0 else{
alert(message: "메모를 입력해주세요")
return
}
let newMemo = Memo(content: memo )
Memo.dummyMemoList.append(newMemo)
NotificationCenter.default.post(name:ComposeViewController.newMemoDidInsert, object: nil)
dismiss(animated: true, completion: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
}
extension ComposeViewController{
//라디오방송 -> 방송국에 해당하는 notificationCenter
static let newMemoDidInsert = Notification.Name(rawValue: "newMemoDidInsert")
}