Skip to content

Instantly share code, notes, and snippets.

View volkanbicer's full-sized avatar
🔥

Volkan Bicer volkanbicer

🔥
View GitHub Profile
class StoreViewController: UIViewController {
typealias Factory = BooksViewControllerBuilder
private let factory: Factory
init(_ factory: Factory) {
self.factory = factory
super.init(nibName: nil, bundle: nil)
}
required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") }
class StoreViewController: UIViewController {
typealias Factory = BooksViewControllerBuilder & VideosViewControllerBuilder
private let factory: Factory
init(_ factory: Factory) {
self.factory = factory
super.init(nibName: nil, bundle: nil)
}
required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") }
class VideosViewController: UIViewController {
}
protocol VideosViewControllerBuilder {
func build() -> VideosViewController
}
extension DependencyContaier: VideosViewControllerBuilder {
func build() -> VideosViewController {
struct Book {
let id: String
let name: String
let author: String
}
typealias Books = [Book]
protocol BooksViewControllerBuilder {
func build() -> BooksViewContoller
}
extension DependecyContainer: BooksViewControllerBuilder {
func build() -> BooksViewContoller {
return BooksViewContoller(bookService: bookService, auth: auth)
}
}
struct DependecyContainer {
private let bookService: BookService
private let auth: Auth
init(bookService: BookService = MockBookService(),
auth: Auth = MockAuth()) {
self.bookService = bookService
self.auth = auth
}
}
class MockBookService: BookService {
func fetchPopularBooks(then handler: (Books) -> Void) {
let books = [
Book(id: "1", name: "X", author: "X"),
Book(id: "2", name: "Y", author: "Y"),
Book(id: "3", name: "Z", author: "Z")
]
handler(books)
}
protocol BookService {
typealias Handler = (Books) -> Void
// Global popular books (Anonymous)
func fetchPopularBooks(then handler: Handler)
// Special books based on logged in user preferences
func fetchRelatedBooks(then handler: Handler)
}
@volkanbicer
volkanbicer / gittips.txt
Last active July 26, 2018 11:14
Advanced git tips
# Move commit from one branch to another.
git checkout dev
git cherry-pick 12345
git checkout master
git reset 12345
# Git reset
@volkanbicer
volkanbicer / appStoreCustomizer.js
Created July 11, 2018 08:13
ITunes charts customizer.
function removeByCategory(category){
let allLinks = document.getElementsByTagName('a')
let links = []
for(let i = 0; i<allLinks.length; i++){
if(allLinks[i].text === category){
links.push(allLinks[i])
}
}