Skip to content

Instantly share code, notes, and snippets.

View tifoaudii's full-sized avatar
🎯
Focusing

Tifo Audi A.P tifoaudii

🎯
Focusing
View GitHub Profile
let fileName: String = "TokenExtension.swift"
let destinationUrl = "\(FileManager.default.currentDirectoryPath)/\(fileName)"
do {
try tokenExtension.write(toFile: destinationUrl, atomically: true, encoding: .utf8)
print("Token Extension is successfully generated:\n \(destinationUrl)\n")
} catch {
print(error)
}
func traverse(dictionary: [String : Any], parent: String) -> String {
if dictionary.keys.contains("type") {
let type = dictionary["type"] as! String
let tokenType: TokenType = TokenType(value: type)
switch tokenType {
case .color:
let value = dictionary["value"] as! String
let variableValue = "UIColor.hexColor(\"\(value)\") ?? .black"
return createVariable(dataType: tokenType.dataType, variableName: parent.camelCased(with: "."), value: variableValue)
case .typography:
{
"Color": {
"red": {
"light": {
"value": "#FFCCCB",
"type": "color"
},
"regular": {
"value": "#880808",
"type": "color"
guard let fileUrl = Bundle.main.url(forResource: "Token", withExtension: "json") else {
return
}
guard let jsonData = try? Data(contentsOf: fileUrl) else {
return
}
guard let object = try? JSONSerialization.jsonObject(with: jsonData, options: .fragmentsAllowed),
let dictionary = object as? [String : Any] else {
import Foundation
@main
struct SampleScript {
static func main() {
print("execute script! ")
}
}
final class SomeViewController: UIViewController {
typealias GetCardModelsCompletion = (Result<[CardModel], Error>) -> Void
typealias GetCardModels = (@escaping GetCardModelsCompletion) -> Void
private var cards: [CardModel] = []
private let getCardModels: GetCardModels
init(getCardModels: @escaping GetCardModels) {
self.getCardModels = getCardModels
final class SomeViewController: UIViewController {
private var cards: [CardModel] = []
private let cardService: CardModelService
init(cardService: CardModelService) {
self.cardService = cardService
super.init(nibName: nil, bundle: .main)
}
struct CardModel {}
protocol CardModelService {
func fetchCardModels(completion: @escaping (Result<[CardModel], Error>) -> Void)
}
class HomeService: CardModelService {
static let shared = HomeService()
private init() {}
struct CardModel {}
class HomeService {
static let shared = HomeService()
private init() {}
func fetchHomeCardModels(completion: @escaping (Result<[CardModel], Error>) -> Void) {
// ...
}
final class SomeViewController: UIViewController {
var isFromHome = false
var isFromCart = false
var isFromProfile = false
var homeService: HomeService = .shared
var cartService: CartService = .shared
var profileService: ProfileService = .shared