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
class CommentViewController : UITableViewController { | |
// 投稿データ. | |
var post: Post? | |
} |
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
class TimelineCell : UITableViewCell { | |
// 省略.. | |
// いいねがタップされた時に呼び出す、コールバック. | |
var likeCallback: ((Post) -> Void)? | |
// いいねボタンがタップされた. | |
@IBAction func onTapLike(_ sender: Any) { | |
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
// MyPageViewController.swift | |
import UIKit | |
// UICollectionViewのデザインレイアウトを指定する. | |
extension MyPageViewController: UICollectionViewDelegateFlowLayout { | |
func collectionView(_ collectionView: UICollectionView, | |
layout collectionViewLayout: UICollectionViewLayout, | |
sizeForItemAt indexPath: IndexPath) -> CGSize { |
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
// MyPageViewController.swift | |
import UIKit | |
extension MyPageViewController { | |
// セクション数を返します. | |
override func numberOfSections(in collectionView: UICollectionView) -> Int { | |
return 1 |
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
// MyPageViewController.swift | |
import UIKit | |
class MyPageViewController : UICollectionViewController { | |
// 自分が投稿した一覧. | |
var posts: [Post] = [] { | |
didSet { |
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
extension UIViewController { | |
// 省略.. | |
// ローディングを表示します. | |
func showProgress() { | |
// ローディングを作成します. | |
let indicator = UIActivityIndicatorView() | |
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
// 投稿API. | |
static func post(image: UIImage, text: String, callback: @escaping((String?) -> Void)) { | |
// APIトークンがない場合はエラー. | |
guard let apiToken = UserDefaults.standard.string(forKey: "apiToken") else { | |
callback("ログインが必要です") | |
return | |
} | |
// 送信先URLを作成します. |
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
import UIKit | |
class PostViewController : UIViewController { | |
// 省略.. | |
override func viewDidLoad() { | |
// textView の Delegate 設定. | |
self.textView.delegate = self |
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
import UIKit | |
class PostViewController : UIViewController { | |
@IBOutlet weak var userImageView: UIImageView! | |
@IBOutlet weak var textView: UITextView! | |
// 「カメラを起動する」がタップされた. | |
@IBAction func onTapCamera(_ sender: Any) { |
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
// UIImageViewの拡張. | |
extension UIImageView { | |
// 指定URLから画像をダウンロードして、表示します(ダウンロード先を文字列で指定). | |
func downloadedFrom(path: String, contentMode mode: UIView.ContentMode = .scaleAspectFit) { | |
// http:// から始まるフルパスにする. | |
let urlString = apiRoot + path | |
guard let url = URL(string: urlString) else { return } |