Skip to content

Instantly share code, notes, and snippets.

View thiagolioy's full-sized avatar

Thiago Lioy thiagolioy

View GitHub Profile
import UIKit
protocol ItemsTableViewDatasource: UITableViewDataSource {
associatedtype T
var items:[T] {get}
weak var tableView: UITableView? {get}
weak var delegate: UITableViewDelegate? {get}
init(items: [T], tableView: UITableView, delegate: UITableViewDelegate)
final class CharactersDatasource: NSObject, ItemsTableViewDatasource {
var items:[Character] = []
weak var tableView: UITableView?
weak var delegate: UITableViewDelegate?
required init(items: [Character], tableView: UITableView, delegate: UITableViewDelegate) {
self.items = items
self.tableView = tableView
self.delegate = delegate
protocol ReusableTableViewCell {
}
extension ReusableTableViewCell where Self: UITableViewCell {
static func cellIdentifier() -> String {
return String(describing: Self.self)
}
import UIKit
import Kingfisher
extension UIImageView {
func download(image url: String) {
guard let imageURL = URL(string:url) else {
return
}
self.kf.setImage(with: ImageResource(downloadURL: imageURL))
}
final class CharacterTableCell: UITableViewCell, NibReusable {
@IBOutlet weak var name: UILabel!
@IBOutlet weak var thumb: UIImageView!
static func height() -> CGFloat {
return 80
}
func setup(item: Character) {
name.text = item.name
func navigateExample() {
guard let nextController = Storyboard.Main.characterViewControllerScene
.viewController() as? CharacterViewController else {
return
}
let character = characters[index.row]
nextController.character = character
self.navigationController?.pushViewController(nextController, animated: true)
}
@thiagolioy
thiagolioy / Podfile
Created November 27, 2016 14:13
Podfile for tests blog post
# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'
target 'Marvel' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
plugin 'cocoapods-keys', {
:project => "Marvel",
:keys => [
@thiagolioy
thiagolioy / Gemfile
Created November 27, 2016 15:11
Gemfile blog post test project
# frozen_string_literal: true
source "https://rubygems.org"
# gem "rails"
gem "cocoapods", "1.1.1"
gem "cocoapods-keys", "1.7.0"
gem "slather", "2.3.0"
gem "fastlane", "1.110.0"
@thiagolioy
thiagolioy / Fastfile
Last active November 27, 2016 15:21
Fastfile of blog post
fastlane_version "1.110.0"
default_platform :ios
platform :ios do
before_all do
# ENV["SLACK_URL"] = "https://hooks.slack.com/services/..."
cocoapods
end
@thiagolioy
thiagolioy / MockLoader.swift
Created November 27, 2016 20:04
blog post tests, MockLoader
import Foundation
import ObjectMapper
@testable import Marvel
struct MockLoader {
let data: Data
let json: String
init?(file: String, withExtension fileExt: String = "json", in bundle:Bundle = Bundle.main) {