Skip to content

Instantly share code, notes, and snippets.

View bannzai's full-sized avatar
スターください

bannzai bannzai

スターください
View GitHub Profile
@bannzai
bannzai / InfinitePlayView.swift
Created October 19, 2019 16:33
InfinitePlayView
public class VideoPlayerView: UIView {
fileprivate let resourcePath: String
fileprivate let fileExtension: String
fileprivate let asset: AVAsset
fileprivate let playerItem: AVPlayerItem
fileprivate let player: AVPlayer
public required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") }
public init(resourcePath: String, ofType: String) {
self.resourcePath = resourcePath
@bannzai
bannzai / swiftui.swift
Last active October 3, 2019 11:07
SwiftUI with SwiftDSL vs SwiftUI not SwiftDSL
import UIKit
import SwiftUI
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
self.window = window
}
import Foundation
// Library A start
public typealias MediaSourceConnection = Any
public struct MediaEvent<T> {
init<T>(_ t: T) { }
}
public protocol MediaSink: AnyObject {
associatedtype InputMedia
@bannzai
bannzai / ti.swift
Created August 8, 2019 02:15
Type inference
let odd = [1,2,3].filter { $0 % 2 == 1 }
let numbers: [Int] = [1,2,3]
let odd: [Int] = numbers.filter { (number: Int) -> Bool in
return number % 2 == 1
}
@bannzai
bannzai / init_swizzle.swift
Created July 16, 2019 17:26
init swizzling for swift.
public class Model: NSObject {
@objc dynamic init(x: Int) {
print("x: \(x)")
}
@objc dynamic init(y: Int) {
print("y: \(y)")
}
}
@bannzai
bannzai / FunctionParameterSyntax.swift
Created April 19, 2019 05:20
FunctionParameterSyntax
public struct FunctionParameterSyntax: Syntax, _SyntaxBase, Hashable {
enum Cursor: Int {
case attributes
case firstName
case secondName
case colon
case type
case ellipsis
case defaultArgument
case trailingComma
@bannzai
bannzai / swift.swift
Created April 18, 2019 10:39
Part of Ragnarok
let comma = SyntaxFactory.makeCommaToken(
trailingTrivia: [.newlines(lineBreakCount), .spaces(trailingIndent)]
)
newParamter = newParamter.withTrailingComma(comma)
@bannzai
bannzai / SyntaxFactory.swift
Created January 29, 2019 03:19
SwiftSyntaxGeneratedFiles version 0.4.2
//// Automatically Generated From SyntaxFactory.swift.gyb.
//// Do Not Edit Directly!
//===------- SyntaxFactory.swift - Syntax Factory implementations ---------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
@bannzai
bannzai / json
Created January 20, 2019 06:40
with default argument
{
"kind": "SourceFile",
"layout": [
{
"kind": "CodeBlockItemList",
"layout": [
{
"kind": "CodeBlockItem",
"layout": [
{
@bannzai
bannzai / swift-syntax-output.json
Last active January 20, 2019 07:40
swift-syntax-output
{
"kind": "SourceFile",
"layout": [
{
"kind": "CodeBlockItemList",
"layout": [
{
"kind": "CodeBlockItem",
"layout": [
{