Skip to content

Instantly share code, notes, and snippets.

View thepearl's full-sized avatar
💭
I may be slow to respond.

Ghazi Tozri thepearl

💭
I may be slow to respond.
View GitHub Profile
import Foundation
import SwiftUI
import Combine
// MARK: - Presentation Layer
struct MyView: View {
@ObservedObject var viewModel: MyViewModel
var body: some View {
import Foundation
import SwiftUI
import Combine
protocol Networking {
func fetch() -> String?
}
class NetworkManager: Networking {
// Some code for making network requests
func fetch() -> String? {
import Foundation
import SwiftUI
import Combine
// MARK: - Presentation Layer
struct MyView: View {
@ObservedObject var viewModel: MyViewModel
var body: some View {
@thepearl
thepearl / TNRegPhoneVerification
Created June 13, 2021 14:10
Regex to validate Tunisian mobile numbers
السلام عليكم ، هذا كود ريجيكس بسيط للتحقق من صحة أرقام الجوالات التونسية ، يقوم الريجيكس بالتحقق من مفتاح الدولة ، مفتاح شركة الإتصالات لضمان صحة النص المدخل .
Hello, this is a simple regex to validate tunisian mobile numbers, the code will validate country code, telecome company code and make sure the tested sting is correct .
"^(00216|216|\+216)(9|5|4|2)([0-9]{7})$"
Regex Breakdown - شرح الكود
-----
@thepearl
thepearl / MainView.swift
Created January 14, 2021 17:47
final version of MainView
//
// View.swift
// iOSDiffableDataSource
//
// Created by Ghazi Tozri on 9/1/2021.
//
import UIKit
import Combine
@thepearl
thepearl / Observers.swift
Created January 14, 2021 17:45
DIFFABLE DS
//MARK: - Observers
extension MainView
{
func setupObservers()
{
// MONITOR search bar textfield keystrokes
$keyStroke
.receive(on: RunLoop.main)
.sink { (keyWordValue) in
print(keyWordValue)
@thepearl
thepearl / ViewModel.swift
Created January 14, 2021 17:26
Final version of ViewModel
import UIKit
import Combine
class ViewModel
{
var cancellables: Set<AnyCancellable> = []
init()
{
$keyWordSearch.receive(on: RunLoop.main).debounce(for: .seconds(0.5), scheduler: RunLoop.main)
@thepearl
thepearl / Service.swift
Created January 14, 2021 17:07
Networking call
import UIKit
class Service
{
let API_KEY = "k_0hpcd8sn"
let endpoint = "https://imdb-api.com/en/API/SearchMovie/"
static var sharedInstance = Service()
private init(){}
@thepearl
thepearl / ViewModel.swift
Last active January 14, 2021 17:12
ViewModel init
import UIKit
import Combine
class ViewModel
{
var cancellables: Set<AnyCancellable> = []
init()
{
$keyWordSearch
@thepearl
thepearl / MainView.swift
Last active January 14, 2021 16:52
setting up observers
import UIKit
import Combine
class MoviesTableViewDiffableDataSource: UITableViewDiffableDataSource<String?, Result> {}
class MainView: UIViewController
{
var cancellables: Set<AnyCancellable> = []
@IBOutlet weak var searchBar: UISearchBar!