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 / 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
func sumRecursively(numbers: [Int], _ acc:Int = 0) -> Int {
if let head = numbers.first {
let tail = Array(dropFirst(numbers))
return sumRecursively(tail, head + acc)
} else {
return acc
}
}
let myNumbers = [1,2,3,4,5]
@tvidenov
tvidenov / AppDelegate.swift
Last active June 8, 2016 09:56 — forked from asciimike/AppDelegate.swift
Zero to App: Develop with Firebase (for iOS - Google I/O 2016)
///
// AppDelegate.swift
// ZeroToApp
//
import UIKit
import Firebase
import FBSDKCoreKit
@UIApplicationMain