Skip to content

Instantly share code, notes, and snippets.

View dejanskledar's full-sized avatar

Dejan Skledar dejanskledar

View GitHub Profile
@dejanskledar
dejanskledar / 0_reuse_code.js
Created June 3, 2016 07:27
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@dejanskledar
dejanskledar / Swift4Codable.swift
Last active September 25, 2017 12:17
Swift 4 Codable Protocol example in Playground
//
// Created by Dejan Skledar
// Equaleyes Solutions Ltd.
//
import UIKit
struct Sword: Codable {
private enum CodingKeys: String, CodingKey {
guard let tabItems = tabBar.items else { return }
tabItems[0].titlePositionAdjustment = UIOffset(horizontal: -15, vertical: 0)
tabItems[1].titlePositionAdjustment = UIOffset(horizontal: 15, vertical: 0)
middleButton.frame.size = CGSize(width: 70, height: 70)
middleButton.backgroundColor = .blue
middleButton.layer.cornerRadius = 35
middleButton.layer.masksToBounds = true
middleButton.center = CGPoint(x: UIScreen.main.bounds.width / 2, y:
UIScreen.main.bounds.height - 40)
view.addSubview(middleButton)
middleButton.center = CGPoint(x: tabBar.frame.width / 2, y: 10)
tabBar.addSubview(middleButton)
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
let from = point
let to = middleButton.center
return sqrt((from.x - to.x) * (from.x - to.x) + (from.y - to.y) * (from.y - to.y)) <= 35 ? middleButton : super.hitTest(point, with: event)
}
typealias Codable = Decodable & Encodable
protocol Encodable {
func encode(to encoder: Encoder) throws
}
protocol Decodable {
init(from decoder: Decoder) throws
}
struct Sword: Codable {
let name: String
let size: Int
let isValyrianSteel: Bool
}
let oathKeeper = Sword(name: "Oathkeeper", size: 120, isValyrianSteel: true)
let jsonData = try? JSONEncoder().encode(oathKeeper)