Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View darrarski's full-sized avatar
:octocat:
🍏🦕

Dariusz Rybicki darrarski

:octocat:
🍏🦕
View GitHub Profile
@darrarski
darrarski / CustomIntensityVisualEffectView.swift
Last active April 23, 2024 08:32
UIVisualEffectView subclass that allows to customise effect intensity
import UIKit
final class CustomIntensityVisualEffectView: UIVisualEffectView {
/// Create visual effect view with given effect and its intensity
///
/// - Parameters:
/// - effect: visual effect, eg UIBlurEffect(style: .dark)
/// - intensity: custom intensity from 0.0 (no effect) to 1.0 (full effect) using linear scale
init(effect: UIVisualEffect, intensity: CGFloat) {
theEffect = effect
@darrarski
darrarski / FormattedTextField.swift
Last active April 16, 2024 13:14
SwiftUI FormattedTextField - TextField with custom display/edit formatters
import SwiftUI
public struct FormattedTextField<Formatter: TextFieldFormatter>: View {
public init(_ title: String,
value: Binding<Formatter.Value>,
formatter: Formatter) {
self.title = title
self.value = value
self.formatter = formatter
}
@darrarski
darrarski / SwiftUI_SizeChangeModifier.swift
Last active February 14, 2024 17:08
Swift UI vie modifier for retrieving the view size
import SwiftUI
public extension View {
func onSizeChange(
ignoreSafeArea: Bool = false,
round: Bool = false,
perform action: @escaping (CGSize) -> Void
) -> some View {
modifier(SizeChangeModifier(
ignoreSafeArea: ignoreSafeArea,
@darrarski
darrarski / EmojiPicker.swift
Last active February 11, 2024 17:10
SwiftUI emoji picker using UIKit on iOS
import SwiftUI
struct EmojiPickerView: UIViewRepresentable {
@Binding var isFirstResponder: Bool
var onPick: (String) -> Void
var onDelete: () -> Void
func makeUIView(context: Context) -> UIViewType {
UIViewType(view: self)
}
@darrarski
darrarski / FetchedResultsPublisher.swift
Last active November 9, 2023 08:31
Swift-Combine-CoreData-Fetched-Results-Publisher
import Combine
import CoreData
public final class FetchedResultsPublisher
<ResultType>
: Publisher
where
ResultType: NSFetchRequestResult
{
@darrarski
darrarski / SwiftUI_onInterfaceOrientationChange.swift
Created August 23, 2021 10:50
SwiftUI view modifier that performs action when UIInterfaceOrientation changes
import SwiftUI
public extension View {
/// Perform action when interface orientation of the view changes
/// - Parameter perform: Action to perform
/// - Returns: Modified view
func onInterfaceOrientationChange(perform: @escaping (UIInterfaceOrientation) -> Void) -> some View {
modifier(OnInterfaceOrientationChangeViewModifier(onChange: perform))
}
}
@darrarski
darrarski / NumberField.swift
Last active October 18, 2023 18:10
SwiftUI NumberField - TextField with custom display/edit number formatters
import SwiftUI
public struct NumberField: View {
public init(_ title: String,
value: Binding<NSNumber?>,
decorator: @escaping (String) -> String = { $0 }) {
self.title = title
self.value = value
let formatter = NumberFormatter()
@darrarski
darrarski / Gravatar.swift
Created August 31, 2023 14:10
Swift wrapper for Gravatar JSON API
import CryptoKit
import Dependencies
import Foundation
import XCTestDynamicOverlay
public struct GravatarJSON: Equatable, Sendable, Codable {
public init(entry: [Entry]) {
self.entry = entry
}
@darrarski
darrarski / ReducerPrinter+SwiftLog.swift
Created August 9, 2023 13:56
ComposableArchitecture + SwiftLog integration
import ComposableArchitecture
import Logging
extension _ReducerPrinter {
/// Logs info about received actions and state changes to swift-log's Logger with provided label.
///
/// Example usage:
/// ```
/// let store = Store(initialState: AppFeature.State()) {
/// AppFeature()._printChanges(.swiftLog(label: "tca"))
@darrarski
darrarski / FuncUtils.swift
Created February 13, 2019 02:13
Functional programming helpers for Swift
// swiftlint:disable identifier_name
// MARK: - ForwardApplication
precedencegroup ForwardApplication {
associativity: left
higherThan: AssignmentPrecedence
}
infix operator |>: ForwardApplication