Skip to content

Instantly share code, notes, and snippets.

@BestKora
BestKora / BottomSheet.swift
Last active March 21, 2020 18:05
Control vertical move of the ScrollView in SwiftUI.
import SwiftUI
import Combine
public struct BottomSheet<Content>: View where Content : View {
/// The content of the scroll view.
public var content: Content
/// The offset of the scrollview updated as the scroll view scrolls
@Binding public var offset : CGSize
@BestKora
BestKora / FunctionalJSON.playground.swift
Last active August 29, 2015 14:12
Код к статье Chris Eidhof "JSON parsing in Swift" http://chris.eidhof.nl/posts/json-parsing-in-swift.html с улучшенной функцией печати на Playground.
// This code accompanies a blog post: http://chris.eidhof.nl/posts/json-parsing-in-swift.html
//
// As the >>= operator is already defined, so I changed it to >>>=
import Foundation
let parsedJSON : [String:AnyObject] = [
"stat": "ok",
"blogs": [
@BestKora
BestKora / FunctionalSwift.playground.swift
Last active August 29, 2015 14:12
Код к выступлению Chris Eidhof на встрече SLUG группы http://realm.io/news/functional-programming-swift-chris-eidhof/
// This code accompanies a Swift meetup video on Realm: http://realm.io/news/functional-programming-swift-chris-eidhof/
//
// As the >>= operator is already defined, so I changed it to >>>=
import Foundation
let parsedJSON : [String:AnyObject] = [
"stat": "ok",
"blogs": [
@BestKora
BestKora / TrailingClosure.playground.swift
Created November 6, 2014 19:38
Follow article "Swift: The Problem with Trailing Closure Syntax" http://natashatherobot.com/swift-trailing-closure-syntax/#
// Playground - noun: a place where people can play
import Foundation
import UIKit
//~~~~~~~~~~~~~~~~ Error handling with enum Result<A> ~~~~~~~
enum Result<A> {
case Error(NSError)
case Value(Box<A>)
extension String {
func toEnum<Enum: RawRepresentable where Enum.RawValue == String>() -> Enum? {
return Enum(rawValue: self)
}
}
class ViewController: UIViewController {
.............
@BestKora
BestKora / EfficientJSON.playground.swift
Last active August 29, 2015 14:07
Код к статье "Эффективный JSON с функциональными концепциями и дженериками в Swift" http://www.bestkora.com/SwiftLearning/effektivnyj-json-v-swift-s-funtsionalnymi-kontseptsiyami-i-dzhenerikami/
// Playground - noun: a place where people can play
import Foundation
/*let parsedJSON : [String:AnyObject] = [
"id": 1,
"name": "Cool User",
"email": "u.cool@example.com"
]
@BestKora
BestKora / ErrorHandling.playground.swift
Last active August 29, 2015 14:07
Код к серии статей "Управление ошибками в Swift: магия и реальность. http://www.bestkora.com/SwiftLearning/upravlenie-oshibkami-v-swift-magiya-i-realn/
// Playground - noun: a place where people can play
import Foundation
// ДЛЯ СТАТЬИ http://nomothetis.svbtle.com/error-handling-in-swift
// Управление ошибками в Swift: магия и реальность - Часть 2
// http://www.bestkora.com/SwiftLearning/upravlenie-oshibkami-v-swift-magiya-i-realn/
// ============= Обычная функция ===========
func divide0 (a: Float, by: Float ) -> Float {