Skip to content

Instantly share code, notes, and snippets.

View surakamy's full-sized avatar

Dmytro Kholodov surakamy

View GitHub Profile
@surakamy
surakamy / AdaptiveStepper.swift
Created November 13, 2019 18:05
Adaptive Stepper SwiftUI
import SwiftUI
struct AdaptiveStepper: View {
@State var refresh: Bool = false
@Binding var selection: Int
init(selection: Binding<Int>) {
@surakamy
surakamy / ItunesSearchRequestCombine.swift
Created November 12, 2019 11:36
URL request with Combine
import SwiftUI
import Combine
struct Response: Codable {
var results: [Result]
}
struct Result: Codable {
var trackId: Int
var trackName: String
@surakamy
surakamy / swiftui-logo-animation.swift
Created October 28, 2019 08:48
SwiftUI animation demo
import SwiftUI
struct Vector: VectorArithmetic {
static func -= (lhs: inout Vector, rhs: Vector) {
lhs = lhs - rhs
}
static func - (lhs: Vector, rhs: Vector) -> Vector {
Vector(points: zip(lhs.points, rhs.points).map { $0.0 - $0.1 } )
}
@surakamy
surakamy / swift_alert_in_enum.swift
Last active July 17, 2021 20:06
SwiftUI Alert example using enum
import SwiftUI
enum Message {
/// A message and OK button
case information(body: String)
/// A message and OK button
case warning(body: String)
/// A question with YES and NO buttons
case confirmation(body: String, action: () -> Void)
/// A question about destractive action with `action` and CANCEL buttons
//
// ContentView.swift
// UnitCoverter
//
// Created by roblack on 10/12/19.
// Copyright © 2019 roblack. All rights reserved.
//
/// TODO: remove ContentViewUnitExtensions.swift
@surakamy
surakamy / DarkLightModeDynamicColors.swift
Created July 16, 2019 19:33
Dynamic colors for Dark and Light modes.
// Examples
UIColor.red.tweaked
UIColor.blue.lighter
extension UIColor {
/// Color gets darker in Light mode and lighter in Dark mode.
@objc var tweaked: UIColor {
if #available(iOS 13.0, *) {
switch UIApplication.userInterfaceStyle {
@surakamy
surakamy / Array+splitAtIndices.swift
Last active February 12, 2018 20:53
Extension to Array - split at indices
extension Array {
/// Returns the longest possible subsequences of the collection, in order,
/// that don't contain elements at indices provided.
///
/// The resulting array consists of at most `maxSplits + 1` subsequences.
/// Elements that are used to split the sequence are not returned as part of
/// any subsequence.
///
/// - Parameters:
/// - maxSplits: The maximum number of times to split the collection, or
# Refresh local information about remote branches.
git remote update --prune
# Fetch new remote branches
git fetch --all
@surakamy
surakamy / UIViewController+Embedded.swift
Last active March 13, 2017 19:33
Extension of UIViewController with helpers methods to simplify embedding child view controllers. <Swift 3.0.2>
/*
MIT License
Copyright © 2017 Dmytro Kholodov
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@surakamy
surakamy / generic_closures.swift
Last active December 4, 2016 13:51
Swift generic typealias
typealias Closure<I, O> = (I) -> O
let lambda: Closure<Int, String> = { intValue in
return "\(intValue) * \(intValue) = \(intValue*intValue)"
}