Skip to content

Instantly share code, notes, and snippets.

View Rsych's full-sized avatar
🙈
I may be slow to respond.

J. W. Kim Rsych

🙈
I may be slow to respond.
View GitHub Profile
@Rsych
Rsych / Extension-View-Popup.swift
Created February 2, 2022 21:57
Custom popup extension
import SwiftUI
extension View {
public func popup<PopupContent: View>(
isPresented: Binding<Bool>,
view: @escaping () -> PopupContent) -> some View {
self.modifier(
Popup(
isPresented: isPresented,
@Rsych
Rsych / Extension-Popover.swift
Created February 2, 2022 21:53
Custom size Popover extension
import SwiftUI
struct PopoverViewModifier<PopoverContent>: ViewModifier where PopoverContent: View {
@Binding var isPresented: Bool
let onDismiss: (() -> Void)?
let content: () -> PopoverContent
func body(content: Content) -> some View {
content
.background(
import SwiftUI
struct DetailLoadingView: View {
@Binding var coin: Coin?
init(coin: Binding<Coin?>) {
_coin = coin
print("Itit detail loading view for \(coin.wrappedValue?.name)")
}
var body: some View {
@Rsych
Rsych / CombineFilter.swift
Created January 20, 2022 11:58
Filtering with Combine
import Foundation
import Combine
class HomeViewModel: ObservableObject {
@Published var allCoins: [Coin] = []
@Published var portfolioCoins: [Coin] = []
@Published var searchText: String = ""
private let dataService = CoinDataService()
@Rsych
Rsych / UIApplication.swift
Created January 20, 2022 08:58
Dismiss keyboard UIApplication extension
import UIKit
extension UIApplication {
// dismiss keyboard
func endEditing() {
sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
}
}
import SwiftUI
struct SearchBarView: View {
// MARK: - Properties
@Binding var searchText: String
// MARK: - Body
var body: some View {
HStack {
Image(systemName: "magnifyingglass")
.foregroundColor(
import Foundation
import UIKit
import Combine
class CoinImageService {
@Published var image: UIImage? = nil
private var imageSubscription: AnyCancellable?
import Foundation
import UIKit
class LocalFileManager {
static let instance = LocalFileManager()
private init() { }
func saveImage(image: UIImage, imageName: String, folderName: String) {
// Create folder if not exist
createFolder(folderName: folderName)
@Rsych
Rsych / ViewModel.swift
Last active January 19, 2022 19:52
Networking ViewModel
import Foundation
import Combine
class HomeViewModel: ObservableObject {
@Published var allCoins: [Coin] = []
@Published var portfolioCoins: [Coin] = []
private let dataService = CoinDataService()
private var cancellable = Set<AnyCancellable>()