Skip to content

Instantly share code, notes, and snippets.

View tobitech's full-sized avatar
🌎
Changing the World

Tobi Omotayo tobitech

🌎
Changing the World
View GitHub Profile
@tobitech
tobitech / ModalViewController.swift
Created November 28, 2018 11:55
Simple flow for pushing another view controller on modal dismiss
protocol ModalViewControllerDelegate {
func pushToAnotherScreen()
}
class ModalViewController: UIViewController {
// MARK: - Properties
weak var delegate: ModalViewControllerDelegate
lazy var cancelButton: UIButton = {
@tobitech
tobitech / APIService.swift
Created August 15, 2019 09:03
APIService examples using Swift 5 Result Type
// model for user profile
struct UserProfile: Codable {
let email: String?
let names: String?
let phone: String?
}
// model for all api response with generic data
struct DataResponse<T: Decodable>: Decodable {
let status: Int?
@tobitech
tobitech / CustomSegmentedControl.swift
Last active December 6, 2019 21:37
A custom segmented control with modern design. Support for Titles, subtitles with and or only images. Can also be used in Interface builder
//
// CustomSegmentedControl.swift
// CustomSegmentedControl
//
// Created by Oluwatobi Omotayo on 06/09/2019.
// Copyright © 2019 Oluwatobi Omotayo. All rights reserved.
//
import UIKit
@tobitech
tobitech / NestableCodingKey.swift
Last active February 12, 2020 01:54 — forked from AliSoftware/Demo.swift
NestableCodingKey: Nice way to define nested coding keys for properties
import Foundation
//: # NestedKey
///
/// Use this to annotate the properties that require a depth traversal during decoding.
/// The corresponding `CodingKey` for this property must be a `NestableCodingKey`
@propertyWrapper
struct NestedKey<T: Decodable>: Decodable {
var wrappedValue: T
struct AnyCodingKey: CodingKey {
@tobitech
tobitech / Timer.swift
Created May 25, 2020 19:14
Count down timer with RxSwift
let timer = Observable<Int>.interval(.seconds(1), scheduler: MainScheduler.instance)
.take(60)
.startWith(0)
.share(replay: 1)
timer
.map { 60 - $0 }
.map { "\($0)" }
.bind(to: timerLabel.rx.text)
.disposed(by: disposeBag)
timer
@tobitech
tobitech / ImageDownloader.swift
Created May 27, 2020 12:05
Reactive ImageDownloader with Alamofire + Cache
//
// ImageDownloader.swift
// ImageDownloader
//
// Created by Oluwatobi Omotayo on 27/05/2020.
// Copyright © 2020 Oluwatobi Omotayo. All rights reserved.
//
import UIKit
import RxSwift
@tobitech
tobitech / WebViewExampleViewController.swift
Created June 10, 2020 21:05 — forked from fxm90/WebViewExampleViewController.swift
Show progress of WKWebView in UIProgressBar that is attached to an UINavigationBar
//
// WebViewExampleViewController.swift
//
// Created by Felix Mau on 06.01.18.
// Copyright © 2018 Felix Mau. All rights reserved.
//
import UIKit
import WebKit
import pandas as pd
from sklearn.tree import DecisionTreeClassifier
music_data = pd.read_csv('music.csv')
X = music_data.drop(columns=['genre'])
y = music_data['genre']
model = DecisionTreeClassifier()
model.fit(X, y)
@tobitech
tobitech / PullDownScrollViewGesture.swift
Last active June 14, 2022 17:31
Implement a pull down gesture on a ScrollView to perform an action in SwiftUI. The idea is to monitor the vertical y offset of the ScrollView.
import SwiftUI
struct OverviewView: View {
private let threshold: CGFloat = 100.0
@State private var showModal = false
var body: some View {
GeometryReader { geometry in
ScrollView(showsIndicators: false) {
VStack {
@tobitech
tobitech / AppView.swift
Last active July 11, 2022 22:43
A SwiftUI app using The Composable Architecture.
import ComposableArchitecture
import SwiftUI
let appReducer: Reducer<AppState, AppAction, AppEnvironment> = Reducer.combine(
onboardingReducer
.optional()
.pullback(
state: \AppState.onboarding,
action: /AppAction.onboarding,
environment: { _ in OnboardingEnvironment() }