Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] Protocol -> BaseView #6

Closed
seungchan2 opened this issue Apr 29, 2022 · 0 comments
Closed

[iOS] Protocol -> BaseView #6

seungchan2 opened this issue Apr 29, 2022 · 0 comments
Assignees
Labels

Comments

@seungchan2
Copy link
Owner

import UIKit

class BaseView: UIView {
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupView()
        setupConstraints()
    }
    
    @available(*, unavailable)
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
    
    func setupView() {}
    func setupConstraints() {}
}

BaseView 설계 이유

  • 처음에는 프로토콜을 사용해서 setupView()와 setupConstraints()를 사용했었음
  • 그럴바엔 하나의 BaseView로 관리하는 게 효율적이라서 체계를 바꿈
  • 필요할 때 override해서 사용하면 됨

예시 코드

//
//  AddPillSecondView.swift
//  SobokSobok
//
//  Created by 김승찬 on 2022/04/29.
//
import UIKit

import SnapKit
import Then

final class FirstView: BaseView {
    
    lazy var nameLabel = UILabel().then {
        $0.text = "HI"
    }
    
    override func setupView() {
        addSubview(nameLabel)
    }
    
    override func setupConstraints() {
        nameLabel.snp.makeConstraints {
            $0.centerX.equalToSuperview()
            $0.centerY.equalToSuperview()
        }
    }
}
@seungchan2 seungchan2 added the iOS label Apr 29, 2022
@seungchan2 seungchan2 changed the title [iOS] BaseView 작업 [iOS] Protocol -> BaseView Apr 29, 2022
@seungchan2 seungchan2 self-assigned this May 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant