Skip to content

Instantly share code, notes, and snippets.

Avatar

Iceman sidepelican

View GitHub Profile
View CollectionViewConcatDataSource.swift
import DiffableDataSources
import UIKit
class CollectionViewConcatDataSource<SectionIdentifierType: Hashable>: NSObject, UICollectionViewDataSource {
typealias ItemIdentifierType = AnyHashable
public typealias SupplementaryViewProvider = (UICollectionView, String, IndexPath) -> UICollectionReusableView?
private var innerDataSource: CollectionViewDiffableDataSource<SectionIdentifierType, AnyHashable>!
private var adapterMap: [SectionIdentifierType: DiffableDataSourceSectionAdapterType] = [:]
var defaultSupplementaryViewProvider: SupplementaryViewProvider? = nil
View dynamicSelf.swift
class A {
class var className: String { "A" }
init() {}
func setup() {
name = {
return Self.className
}
}
var name: (() -> String)?
}
View ObservableType+Paging.swift
extension ObservableType where Element == Void {
func pagenation<
Token,
Source: ObservableConvertibleType,
PagingElement
>(
startWith token: Token,
selector: @escaping (Token) throws -> Source
) -> Observable<(usedToken: Token, PagingElement)>
where
@sidepelican
sidepelican / Iconv.swift
Created May 2, 2020
uses libiconv.2.tbd, swift5.2
View Iconv.swift
import Darwin.POSIX.iconv
class Iconv {
enum Error: Swift.Error {
case illegalByteSequence
case invalidArgument
case invalidResult
case unknownError(errno: Int32)
}
@sidepelican
sidepelican / main.rs
Created Dec 29, 2019
generics function overload
View main.rs
use std::marker::PhantomData;
struct T<A> {
_phantom: PhantomData<A>,
}
impl<U> T<&[U]> {
fn f(_: &[U]) {
println!("f(_: &[U])")
}
View assertStartWithEvent.swift
import RxSwift
import RxCocoa
import UIKit
extension SharedSequence {
func assertStartWithEvent(file: StaticString = #file, line: UInt = #line) -> Self {
let deadline = Observable<Element>.create { observer -> Disposable in
fatalError("Event didn't come immediately after subscribe.", file: file, line: line)
}
.delaySubscription(.nanoseconds(0), scheduler: SharingStrategy.scheduler)
@sidepelican
sidepelican / TypeExtract.swift
Created Sep 17, 2019
雪だるま型パラから型を順番に取り出すやつ
View TypeExtract.swift
import Foundation
protocol _View {
static var specialType: Any.Type { get }
}
protocol View: _View {
associatedtype Body: View
associatedtype Special
var body: Body { get }
View LandmarkDetail.swift
import Combine
import SwiftUI
struct IndexedCollection<Base: RandomAccessCollection>: RandomAccessCollection {
typealias Index = Base.Index
typealias Element = (index: Index, element: Base.Element)
let base: Base
var startIndex: Index { base.startIndex }
@sidepelican
sidepelican / combinationMask.swift
Created Jun 28, 2019
複数パスの図形を反転してマスク
View combinationMask.swift
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
view.backgroundColor = .white
}
@sidepelican
sidepelican / combinationMask.swift
Created Jun 28, 2019
複数パスの図形を反転してマスク
View combinationMask.swift
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
view.backgroundColor = .white
}
You can’t perform that action at this time.