Coder Social home page Coder Social logo

xcodemultiprojectworkspace's Introduction

XcodeMultiProjectWorkspace

https://youtu.be/AfCGqH4tLV4 スクリーンショット_2022_09_24_14_15

import UIKit
import DesignKit
import NetworkKit
import NetworkKitV2

class ViewController: UIViewController {
    
    private let designKit: DesignKit = DesignKitImp()
    private let networkKit = NetworkKitImp()
    
    private lazy var redView: UIView = {
        return designKit.buildView(themeColor: .bgColor1)
    }()

    override func viewDidLoad() {
        super.viewDidLoad()
        setupViews()
        fetchUsers()
    }

    private func setupViews() {
        [redView].forEach(view.addSubview(_:))
        // [redView, UIView(), UIView()].forEach(view.addSubview(_:))
        //        view.addSubview(redView)
        
        NSLayoutConstraint.activate([
            redView.heightAnchor.constraint(equalToConstant: 200),
            redView.widthAnchor.constraint(equalToConstant: 200),
            redView.centerXAnchor.constraint(equalTo: view.centerXAnchor),
            redView.centerYAnchor.constraint(equalTo: view.centerYAnchor)
        ])
    }
    
    private func fetchUsers() {
        Task {
            do {
                let url = URL(string: "https://jsonplaceholder.typicode.com/users")!
                let users: [User] = try await networkKit.get(url: url)
                print(users.first)
            } catch {
                
            }
            

        }
    }

}

struct User: Decodable {
    let name: String
    let email: String
}
import UIKit

public protocol DesignKit {
    func buildRedView() -> UIView
    func buildView(themeColor: ThemeColor) -> UIView
}

public enum ThemeColor {
    case bgColor1
    case bgColor2
    
    var color: UIColor {
        switch self {
        case .bgColor1:
            return .systemIndigo
        case .bgColor2:
            return .systemGray
        }
    }
}

public class DesignKitImp: DesignKit {
    
    public init() {}
    
    public func buildRedView() -> UIView {
        let view = UIView()
        view.backgroundColor = .red
        view.translatesAutoresizingMaskIntoConstraints = false
        return view
    }
    
    public func buildView(themeColor: ThemeColor) -> UIView {
        let view = UIView()
        view.backgroundColor = themeColor.color
        view.translatesAutoresizingMaskIntoConstraints = false
        return view
    }
    
}
import Foundation

public class NetworkKitImp {
    
    public init() {}
    
    public func get<T: Decodable>(url: URL) async throws -> T {
        let (data, _) = try await URLSession.shared.data(from: url)
        let decoder = JSONDecoder()
        return try decoder.decode(T.self, from: data)
    
    }
    
}

xcodemultiprojectworkspace's People

Contributors

yamamotodesu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.