forked from yagom-academy/ios-diary
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ShareDiary 프로토콜 추가 및 delegate 삭제, 오류수정
- Loading branch information
Showing
5 changed files
with
69 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// ShareDiary.swift | ||
// Diary | ||
// | ||
// Created by Max, Hemg on 2023/09/05. | ||
// | ||
|
||
import UIKit | ||
|
||
protocol ShareDiary { | ||
func shareDiary(_ diary: Diary?) | ||
} | ||
|
||
extension ShareDiary where Self: UIViewController { | ||
func shareDiary(_ diary: Diary?) { | ||
guard let diary, | ||
let title = diary.title, | ||
let createdAt = diary.createdAt, | ||
let body = diary.body else { | ||
return | ||
} | ||
|
||
let date = DateFormatter().formatToString(from: createdAt, with: "YYYY년 MM월 dd일") | ||
let shareText = "제목: \(title)\n작성일자: \(date)\n내용: \(body)" | ||
let activityViewController = UIActivityViewController(activityItems: [shareText], applicationActivities: nil) | ||
activityViewController.popoverPresentationController?.sourceView = self.view | ||
|
||
self.present(activityViewController, animated: true, completion: nil) | ||
} | ||
} |