This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum AppAction { | |
case loginButtonTapped | |
case logoutButtonTapped | |
// ... other actions | |
} | |
struct AppState { | |
var isUserLoggedIn: Bool | |
// ... other state properties | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Dependency Inversion Principle: Define protocols for Service and Repository | |
protocol Service { | |
func fetchData() -> String | |
} | |
protocol Repository { | |
func saveData(data: String) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Define protocols for Service and Repository | |
protocol Service { | |
func fetchData() -> String | |
} | |
protocol Repository { | |
func saveData(data: String) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
final class HttpUtility { | |
static let shared = HttpUtility() | |
func get<T: Decodable>(endpoint: String) async throws -> T { | |
let url = URL(string: "https://example.com/api/\(endpoint)")! | |
let (data, _) = try await URLSession.shared.data(from: url) | |
return try JSONDecoder().decode(T.self, from: data) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
// MARK: Project model | |
struct Project: Decodable { | |
let id: Int | |
let name: String | |
let teamId: Int | |
let isActive: Bool | |
enum CodingKeys: String, CodingKey { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// LoginService Protocol | |
protocol LoginService: AnyObject { | |
func authenticateUser(request: LoginRequest) - > UserResponse | |
} | |
// Concrete implementation | |
class LoginServiceImplementation: LoginService { | |
func authenticateUser(request: LoginRequest) - > UserResponse { | |
// create the url request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let dateString = "2022-04-12T18:41:20.000000Z" | |
let dateFormatter = DateFormatter() | |
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ" | |
let result = dateFormatter.date(from: dateString) | |
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" | |
dateFormatter.timeZone = TimeZone(identifier: "UTC") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// let's say the project operation needs to be executed first before the employee | |
let group = DispatchGroup() | |
// employee block operation | |
let employeeBlockOperation = BlockOperation() | |
employeeBlockOperation.addExecutionBlock { | |
let employeeDataResource = EmployeeDataResource() | |
employeeDataResource.getEmployee { (employees) in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// suppose we want to call two apis one after the other then in that case we can use combination of operation queue and dispatch group | |
func syncDataResources() | |
{ | |
let group = DispatchGroup() | |
// employee block operation | |
let employeeBlockOperation = BlockOperation() | |
employeeBlockOperation.addExecutionBlock { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
// MARK: - SyncManager | |
struct SyncManager | |
{ | |
func GetRecordsInSync() | |
{ | |
debugPrint("inside the GetRecordsInSync") | |
let animalOperation = BlockOperation() |
NewerOlder