Skip to content

Instantly share code, notes, and snippets.

View Dimillian's full-sized avatar
📱
SwiftUI EVERYWHERE

Thomas Ricouard Dimillian

📱
SwiftUI EVERYWHERE
View GitHub Profile
@Dimillian
Dimillian / BooksCollectionDataProvider.swift
Last active November 17, 2017 14:02
BooksCollectionDataProvider
protocol BooksCollectionDataProvider {
var title: String { get }
var datasource: [ObjectId] { get }
func loadData(paginationDelegate: PaginationDelegate)
}
class BaseBooksCollectionDataProvider: BooksCollectionDataProvider {
var title: String {
return "No configuration"
}
@Dimillian
Dimillian / BooksCollectionInterfaceProvider.swift
Created November 17, 2017 13:43
BooksCollectionInterfaceProvider.swift
//
// BooksCollectionProvider.swift
// Glose
//
// Created by Thomas Ricouard on 10/11/2017.
// Copyright © 2017 Thomas Ricouard. All rights reserved.
//
import Foundation
import UIKit
@Dimillian
Dimillian / item.cs
Last active September 15, 2017 09:39
public string LongNameAndData
{
get {
string[] description = new String[4];
description[0] = LongName;
if (itemGroup == ItemGroups.Armor) {
description[1] = "Armor Rating: " + GetMaterialArmorValue();
} else if (itemGroup == ItemGroups.Weapons) {
description[1] = "Damage: " + GetBaseDamageMin() + "-" + GetBaseDamageMax();
}
class ReaderWebView: WKWebView {
init(frame: CGRect, asset: ObjectId) {
let conf = WKWebViewConfiguration()
conf.setURLSchemeHandler(GLAssetHandler(), forURLScheme: "glasset")
super.init(frame: frame, configuration: conf)
}
}
@Dimillian
Dimillian / handler.swift
Created August 24, 2017 14:58
WKWebviewURLHandler
import Foundation
import WebKit
class GLAssetHandler: NSObject, WKURLSchemeHandler {
func webView(_ webView: WKWebView, start urlSchemeTask: WKURLSchemeTask) {
//Check that the url path is of interest for you, etc...
//Create a NSURLResponse with the correct mimetype.
let urlResponse = URLResponse(url: url, mimeType: "image/jpeg",
expectedContentLength: -1, textEncodingName: nil)
class Author: Codable {
var name: String?
var slug: String?
}
private func decodeObject<T: Codable>(key: String) -> T? {
guard objectExist(key) else { return nil }
let path = URL(fileURLWithPath: fullPath(key))
do {
let data = try Data(contentsOf: path)
let decoder = PropertyListDecoder()
let object = try decoder.decode(T.self, from: data)
return object
} catch {
print("Decoding error: \(error)")
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
if section <= Sections.count() - Sections.feedOffset() {
let sectionSwitch = Sections(rawValue: section)!
return sectionSwitch.headerView(controller: self)
}
switch filter {
case .books:
return MyBooksTableProvider.Sections(rawValue: section - 2)!.headerView()
default:
return nil
public protocol Dequeueable {
static func id() -> String
static func hasNib() -> Bool
}
public extension UITableView {
func getCell<T: Dequeueable>(forType: T.Type) -> T? {
return dequeueReusableCell(withIdentifier: T.id()) as? T
}
class MyBooksTableProvider {
enum Sections: Int {
case reading, menu, booklists
static func count() -> Int {
return 3
}
func headerView() -> UIView? {