Skip to content

Instantly share code, notes, and snippets.

import Foundation
import RxCocoa
import RxSwift
import SwiftSoup
struct Post {
let id: String
}
class Test {
@Jimmy-Prime
Jimmy-Prime / Podfile
Created May 13, 2019 08:54
Podfile of Crawler project
platform :ios, '11.0'
use_frameworks!
def crawler
pod 'SwiftSoup'
end
def reactivex
pod 'RxCocoa'
@Jimmy-Prime
Jimmy-Prime / .swiftlint.yml
Created May 13, 2019 09:21
Basic SwiftLint config
swiftlint_version: 0.32.0
excluded:
- Pods/
identifier_name:
min_length: 2
line_length:
ignores_comments: true
@Jimmy-Prime
Jimmy-Prime / Zeroes.swift
Created July 9, 2019 06:56
Generate zero array
import Foundation
protocol Zeroes {
static var zero: Self { get }
}
extension Int: Zeroes {}
extension Int8: Zeroes {}
extension Int16: Zeroes {}
extension Int32: Zeroes {}
@Jimmy-Prime
Jimmy-Prime / HeterogeneousListDecoding.swift
Last active January 16, 2020 09:01
Decoding heterogeneous array with Swift Decodable
import Foundation
enum TypeKey: CodingKey {
case type
}
protocol TypeFamily: Decodable {
associatedtype Member: Decodable
var type: Member.Type { get }
}
import Foundation
class SessionDelegate: NSObject, URLSessionDelegate {
func urlSession(
_ session: URLSession,
didReceive challenge: URLAuthenticationChallenge,
completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void
) {
guard challenge.protectionSpace.host != URL.sns.host else {
completionHandler(.performDefaultHandling, nil)
import UIKit
class ViewController: UIViewController {
private var customInput = false
private let textInput = UITextField()
private var leadingBarButtonGroups: [UIBarButtonItemGroup] = []
private var trailingBarButtonGroups: [UIBarButtonItemGroup] = []
override func viewDidLoad() {
super.viewDidLoad()
@Jimmy-Prime
Jimmy-Prime / JSON.swift
Last active May 25, 2020 07:48
JSON Codable
import Foundation
enum JSON {
case null
case bool(Bool)
case int64(Int64)
case double(Double)
case string(String)
indirect case array([JSON])
indirect case dictionary([String: JSON])
import UIKit
class ViewController: UIViewController {
var yearView: UIView?
var currentYear: Int = 2020 {
didSet {
createYearView()
}
}
@Jimmy-Prime
Jimmy-Prime / InfinitePagingScrollViewController.swift
Last active May 14, 2020 09:43
Implementation of infinite scroll
import UIKit
protocol ScrollingContent: Comparable {}
protocol ScrollingContentProvider {
associatedtype Content: ScrollingContent
func previous(of content: Content) -> Content
func next(of content: Content) -> Content
}