Skip to content

Instantly share code, notes, and snippets.

View Shubham0812's full-sized avatar
🎯
Focusing

Shubham Kr. Singh Shubham0812

🎯
Focusing
View GitHub Profile
import UIKit
extension UIColor {
/// For converting Hex-based colors
convenience init(hex: String) {
var hexSanitized = hex.trimmingCharacters(in: .whitespacesAndNewlines)
hexSanitized = hexSanitized.replacingOccurrences(of: "#", with: "")
var rgb: UInt64 = 0
var r: CGFloat = 0.0
import UIKit
extension UIColor {
/// For converting Hex-based colors
convenience init(hex: String) {
var hexSanitized = hex.trimmingCharacters(in: .whitespacesAndNewlines)
hexSanitized = hexSanitized.replacingOccurrences(of: "#", with: "")
var rgb: UInt64 = 0
var r: CGFloat = 0.0
import SwiftUI
extension Color {
init(hex: String) {
self.init(UIColor(hex: hex))
}
}
extension UIColor {
<key>UIAppFonts</key>
<array>
<string>Montserrat-Bold.ttf</string>
<string>Montserrat-Italic.ttf</string>
<string>Montserrat-Medium.ttf</string>
<string>Montserrat-MediumItalic.ttf</string>
<string>Montserrat-Regular.ttf</string>
<string>Montserrat-SemiBold.ttf</string>
<string>Montserrat-SemiBoldItalic.ttf</string>
<string>Montserrat-Thin.ttf</string>
import SwiftUI
enum Montserrat {
case thin
case thinItalic
case regular
case italic
case medium
case mediumItalic
case semibold
import SwiftUI
extension Color {
init(hex: String) {
self.init(UIColor(hex: hex))
}
static func randomColor() -> Color {
return Color(UIColor.random())
import UIKit
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
// MARK:- variables
var window: UIWindow?
// MARK:- functions‹
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
extension HomeViewController: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
guard let pokemons = self.homeViewModel.filteredPokemons.value else { return 0 }
print("new count", pokemons.count)
return pokemons.count
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return PokemonTableViewCell().cellHeight
}
extension HomeViewController: UISearchBarDelegate {
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
searchBar.setShowsCancelButton(true, animated: true)
self.homeViewModel.searchPokemons(with: searchText)
}
func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
self.homeViewModel.resetData()
self.searchBar.text = ""
import UIKit
class HomeViewController: UIViewController {
// MARK:- outlets
@IBOutlet weak var pokemonTableView: UITableView!
// MARK:- variables
var homeViewModel: HomeViewModel!