Skip to content

Instantly share code, notes, and snippets.

View tvidenov's full-sized avatar

Tihomir Videnov tvidenov

View GitHub Profile
@tvidenov
tvidenov / InputField.swift
Created May 29, 2023 10:18 — forked from myurieff/InputField.swift
SwiftUI TCA Validated Input Field
public enum InputField<Value: Equatable> {
/// The state of current input validation
public enum InputValidation: Equatable {
/// A value that has undergone validation and is found to be valid.
case valid(Value)
/// A value that has undergone validation and is found to be invalid.
/// Optionally, a feedback message can be displayed to the user
/// to let them know what the issue with their input is.
/// For example: "Please enter a value between 10 and 100."
case invalid(Value, feedback: String?)
@tvidenov
tvidenov / example.swift
Created February 8, 2023 15:32 — forked from myurieff/example.swift
TCA Inputs Outputs
struct SomeFeature: ReducerProtocol {
struct State: Equatable {}
enum Action: Equatable {
case didAppear
case refreshData
case didComplete
}
struct Input {
var shouldRefresh: () -> AsyncStream<Void>
import SwiftUI
import WebKit
import Combine
class WebViewData: ObservableObject {
@Published var loading: Bool = false
@Published var scrollPercent: Float = 0
@Published var url: URL? = nil
@Published var urlBar: String = "https://nasa.gov"
@tvidenov
tvidenov / grid-trainer.swift
Created July 29, 2022 16:32 — forked from swiftui-lab/grid-trainer.swift
A grid trainer for Grid views
// Author: SwiftUI-Lab (swiftui-lab.com)
// Description: this learning tool is designed to showcase the different
// Grid and GridRow view options, added in SwiftUI 2022. It is part of the
// blog article: https://swiftui-lab.com/grids
import SwiftUI
import UniformTypeIdentifiers
// The root view of the application
struct ContentView: View {
@tvidenov
tvidenov / Localized.swift
Created March 17, 2022 06:43
Localized - handy localization extension
import Foundation
extension String {
var localized: String {
return NSLocalizedString(self, tableName: nil, bundle: Bundle.main, value: "", comment: "")
}
}
@tvidenov
tvidenov / ToSwiftUI.swift
Created March 17, 2022 06:40
SwiftUI wrapper for displaying UIViewControllers in Preview
import SwiftUI
struct ToSwiftUI: UIViewControllerRepresentable {
let viewController: () -> UIViewController
func makeUIViewController(context: Context) -> UIViewController {
self.viewController()
}
@tvidenov
tvidenov / Storyboarded.swift
Created March 17, 2022 06:39
Storyboarded
import UIKit
protocol Storyboarded {
static func instantiate() -> Self
}
extension Storyboarded where Self: UIViewController {
static func instantiate() -> Self {
// this pulls out "MyApp.MyViewController"
let fullName = NSStringFromClass(self)
import Glibc
public struct StderrOutputStream: OutputStreamType {
public mutating func write(string: String) { fputs(string, stderr) }
}
public var errStream = StderrOutputStream()
/**
* Auto-generated code below aims at helping you parse
* the standard input according to the problem statement.
@tvidenov
tvidenov / ios-cell-registration-swift.md
Created June 23, 2016 12:31 — forked from gonzalezreal/ios-cell-registration-swift.md
iOS Cell Registration & Reusing with Swift Protocol Extensions and Generics

iOS Cell Registration & Reusing with Swift Protocol Extensions and Generics

A common task when developing iOS apps is to register custom cell subclasses for both UITableView and UICollectionView. Well, that is if you don’t use Storyboards, of course.

Both UITableView and UICollectionView offer a similar API to register custom cell classes:

public func registerClass(cellClass: AnyClass?, forCellWithReuseIdentifier identifier: String)
public func registerNib(nib: UINib?, forCellWithReuseIdentifier identifier: String)
@tvidenov
tvidenov / JSON.swift
Created June 14, 2016 11:04 — forked from eblaauw/JSON.swift
Swift
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let urlPath = "http://telize.com/geoip"
let url = NSURL(string: urlPath)
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithURL(url!, completionHandler: {data, response, error -> Void in