Blending Culture in Twitter Client

60

Transcript of Blending Culture in Twitter Client

Page 1: Blending Culture in Twitter Client
Page 2: Blending Culture in Twitter Client
Page 3: Blending Culture in Twitter Client
Page 4: Blending Culture in Twitter Client
Page 5: Blending Culture in Twitter Client
Page 6: Blending Culture in Twitter Client
Page 7: Blending Culture in Twitter Client
Page 8: Blending Culture in Twitter Client
Page 9: Blending Culture in Twitter Client
Page 10: Blending Culture in Twitter Client
Page 11: Blending Culture in Twitter Client
Page 12: Blending Culture in Twitter Client
Page 13: Blending Culture in Twitter Client
Page 14: Blending Culture in Twitter Client
Page 15: Blending Culture in Twitter Client
Page 16: Blending Culture in Twitter Client
Page 17: Blending Culture in Twitter Client
Page 18: Blending Culture in Twitter Client
Page 19: Blending Culture in Twitter Client
Page 20: Blending Culture in Twitter Client
Page 21: Blending Culture in Twitter Client
Page 22: Blending Culture in Twitter Client
Page 23: Blending Culture in Twitter Client

class TimelineTableViewController: UITableViewController {

var tweets: [Tweet] = []

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return tweets.count }

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { return UITableViewCell() }

}

Page 24: Blending Culture in Twitter Client

class TimelineTableViewController: UITableViewController { private let timelineDataSource = TimelineDataSource() private let timelineDelegate = TimelineDelegate()

override func viewDidLoad() { tableView.dataSource = timelineDataSource tableView.delegate = timelineDelegate }

Page 25: Blending Culture in Twitter Client

class TimelineDataSource: NSObject, UITableViewDataSource { var tweets: [Tweet] = [] func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return tweets.count }

Page 26: Blending Culture in Twitter Client

import UIKit

class KobitoSettingViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout, KobitoCollectionViewCellDelegate { var delegate: BackDelegate? @IBOutlet weak var kobitoMediumImageView: UIImageView! @IBOutlet weak var kobitoNameLabel: UILabel! @IBOutlet weak var collectionView: UICollectionView! @IBOutlet weak var backButton: UIButton! @IBOutlet weak var gotchaButton: UIButton! var isShowedKobitoDetailView = false var currentSelectedIndex: Int { return KobitoManager.sharedManager.currentKobito.type.rawValue } override func viewDidLoad() { backButton.imageView?.contentMode = .ScaleAspectFit gotchaButton.imageView?.contentMode = .ScaleAspectFit kobitoMediumImageView.image = KobitoManager.sharedManager.currentKobito.type.miniImage kobitoNameLabel.text = KobitoManager.sharedManager.currentKobito.type.name automaticallyAdjustsScrollViewInsets = false var cellSide:CGFloat = 0 var lrMargin:CGFloat = 0 var tbMargin:CGFloat = 0 // これはした方がいいかも. if collectionView.frame.height/2 < collectionView.frame.width/3 { tbMargin = 4 cellSide = (collectionView.frame.size.height - (tbMargin * 4)) / 2 lrMargin = (collectionView.frame.size.width - (cellSide * 3)) / 6 }else { lrMargin = 2 cellSide = (collectionView.frame.size.width - (lrMargin * 6)) / 3 tbMargin = (collectionView.frame.size.height - (cellSide * 2)) / 4 } let layout = UICollectionViewFlowLayout() layout.itemSize = CGSize(width: cellSide, height: cellSide) layout.sectionInset = UIEdgeInsets(top: tbMargin, left: lrMargin, bottom: tbMargin, right: lrMargin) collectionView.collectionViewLayout = layout collectionView.delegate = self collectionView.dataSource = self } override func viewDidAppear(animated: Bool) { showCurrentSelectedMark() } func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAtIndex section: Int) -> CGFloat { return 12 } func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAtIndex section: Int) -> CGFloat { return 0 } func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int { return 1 } func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return 6 } func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {

Page 27: Blending Culture in Twitter Client
Page 28: Blending Culture in Twitter Client
Page 29: Blending Culture in Twitter Client
Page 30: Blending Culture in Twitter Client
Page 31: Blending Culture in Twitter Client
Page 32: Blending Culture in Twitter Client

class Timeline { private var tweets: [Tweet] = [] init(tweets: [Tweet]) { self.tweets = tweets } var numberOfTweet: Int { return tweets.count } subscript(index: Int) -> Tweet { return tweets[index] } private func insertTweetAtIndex(tweet: Tweet, index: Int) { tweets.insert(tweet, atIndex: index) }

Page 33: Blending Culture in Twitter Client

class TimelineDataSource: NSObject, UITableViewDataSource { var timeline: Timeline = Timeline(tweets: []) func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return timeline.numberOfTweet }

Page 34: Blending Culture in Twitter Client
Page 35: Blending Culture in Twitter Client
Page 36: Blending Culture in Twitter Client

struct Timeline { private var tweets: [Tweet] = [] init(tweets: [Tweet]) { self.tweets = tweets } var numberOfTweet: Int { return tweets.count } subscript(index: Int) -> Tweet { return tweets[index] }

Page 37: Blending Culture in Twitter Client

private func insertTweetAtIndex(tweet: Tweet, index: Int) -> Timeline { var mutableTweets = tweets mutableTweets.insert(tweet, atIndex: index) return Timeline(tweets: mutableTweets) }

Page 38: Blending Culture in Twitter Client

func favoriteTweetAtIndex(index: Int) -> Timeline { let cacheTweet = items[index] let tweet = Tweet( id: cacheTweet.id, text: cacheTweet.text, favorited: !cacheTweet.favorited, retweeted: cacheTweet.retweeted, user: cacheTweet.user) return deleteItemAtIndex(index).insertItemAtIndex(tweet, index: index) }

Page 39: Blending Culture in Twitter Client
Page 40: Blending Culture in Twitter Client
Page 41: Blending Culture in Twitter Client

private func insertTweetAtIndex(tweet: Tweet, index: Int) -> Timeline { var mutableTweets = tweets mutableTweets.insert(tweet, atIndex: index) return Timeline(tweets: mutableTweets) }

Page 42: Blending Culture in Twitter Client

private func insertItemAtIndex(item: Item, index: Int) -> Timeline { var mutableItems = Items mutableItems.insert(item, atIndex: index) return Timeline(tweets: mutableItems) }

Page 43: Blending Culture in Twitter Client

protocol DataType { associatedtype ItemType var items: [ItemType] { get } var numberOfItems: Int { get } subscript(index: Int) -> ItemType { get } func insertItemAtIndex(item: ItemType, index: Int) -> Self func deleteItemAtIndex(index: Int) -> Self }

Page 44: Blending Culture in Twitter Client

protocol DataType { associatedtype ItemType var items: [ItemType] { get } var numberOfItems: Int { get } subscript(index: Int) -> ItemType { get } func insertItemAtIndex(item: ItemType, index: Int) -> Self func deleteItemAtIndex(index: Int) -> Self }

Page 45: Blending Culture in Twitter Client

protocol DataType { associatedtype ItemType var items: [ItemType] { get } var numberOfItems: Int { get } subscript(index: Int) -> ItemType { get } func insertItemAtIndex(item: ItemType, index: Int) -> Self func deleteItemAtIndex(index: Int) -> Self }

Page 46: Blending Culture in Twitter Client

protocol DataType { associatedtype ItemType var items: [ItemType] { get } var numberOfItems: Int { get } subscript(index: Int) -> ItemType { get } func insertItemAtIndex(item: ItemType, index: Int) -> Self func deleteItemAtIndex(index: Int) -> Self }

Page 47: Blending Culture in Twitter Client

struct Timeline: DataType { typealias ItemType = Tweet var items: [ItemType] = [] init(items: [ItemType]) { self.items = items } var numberOfItems: Int { return items.count } subscript(index: Int) -> Tweet { return items[index] } func insertItemAtIndex(item: ItemType, index: Int) -> Timeline { var mutableItems = items mutableItems.insert(item, atIndex: index) return Timeline(items: mutableItems) }

Page 48: Blending Culture in Twitter Client

func favoriteTweetAtIndex(index: Int) -> Timeline { let cacheTweet = items[index] let tweet = Tweet( id: cacheTweet.id, text: cacheTweet.text, favorited: !cacheTweet.favorited, retweeted: cacheTweet.retweeted, user: cacheTweet.user) return deleteItemAtIndex(index).insertItemAtIndex(tweet, index: index) }

Page 49: Blending Culture in Twitter Client
Page 50: Blending Culture in Twitter Client
Page 51: Blending Culture in Twitter Client
Page 52: Blending Culture in Twitter Client
Page 53: Blending Culture in Twitter Client
Page 54: Blending Culture in Twitter Client
Page 55: Blending Culture in Twitter Client

_人人人人人人_ > xcode圧力 < ‾Y^Y^Y^Y^Y‾

Page 56: Blending Culture in Twitter Client
Page 57: Blending Culture in Twitter Client
Page 58: Blending Culture in Twitter Client

💪

Page 59: Blending Culture in Twitter Client
Page 60: Blending Culture in Twitter Client