Upgrade to Pro — share decks privately, control downloads, hide ads and more …

『タップル誕生』のコーディング規約 と 検討中のアーキテクチャ

tomohiro_sasaki
October 18, 2017
750

『タップル誕生』のコーディング規約 と 検討中のアーキテクチャ

tomohiro_sasaki

October 18, 2017
Tweet

Transcript

  1. ʰλοϓϧ஀ੜʱͷίʔσΟϯάن໿
    ͱ
    ݕ౼தͷΞʔΩςΫνϟ

    View full-size slide

  2. Profile
    - 2014ʹ৽ଔೖࣾ
    - 2014-2017 ৽نΛ͍Ζ͍Ζ(Unity/Android/iOS)
    - 2017೥3݄ʹʰλοϓϧ஀ੜʱʹJOIN (iOS)
    sasaki tomohiro

    View full-size slide

  3. ίʔσΟϯάن໿

    View full-size slide

  4. ϓϧϦΫग़͠·ͨ͠ʔ
    JOINͨ͠ͱ͖

    View full-size slide

  5. ϓϧϦΫग़͠·ͨ͠ʔ
    JOINͨ͠ͱ͖

    View full-size slide

  6. ϓϧϦΫग़͠·ͨ͠ʔ
    JOINͨ͠ͱ͖
    ͋ɺίʔσΟϯάن໿ͬͯ͋Γ·͔͢ʁ

    View full-size slide

  7. ϓϧϦΫग़͠·ͨ͠ʔ
    JOINͨ͠ͱ͖
    ͋ɺίʔσΟϯάن໿ͬͯ͋Γ·͔͢ʁ
    Α͠ʂ࡞Ζ͏ʂʘ(^o^)ʗ

    View full-size slide

  8. Survey
    - Github
    https://github.com/github/swift-style-guide
    - eureka
    https://github.com/eure/swift-style-guide/blob/master/README_jp.md
    - ϦΫϧʔτϥΠϑελΠϧ
    https://github.com/recruit-lifestyle/swift-style-guide
    - εϚʔτςοΫɾϕϯνϟʔζ
    https://github.com/SmartTechVentures/swift-style-guide
    - Wantedly
    http://qiita.com/susieyy/items/f71435cc962e70d81b37

    View full-size slide

  9. - ࣗݾຬͷίʔσΟϯάن໿ʹ͠ͳ͍
    - ϝϯόʔ͕ࠔ͍ͬͯΔ͜ͱΛղܾ͢Δ
    Important

    View full-size slide

  10. How
    ॻ͖ํΛ೰ΜͰ͍Δ
    Օॴͷऩू
    ٞ࿦ υΩϡϝϯτ࡞੒
    ڞ༗
    = Trello

    View full-size slide

  11. ίʔσΟϯάن໿Λ঺հ

    View full-size slide

  12. ΦϓγϣφϧܕͷnilνΣοΫ
    Ͳ͏͢Δʁ
    if let _ = optionalObject {
    }
    if optionalObject != nil {
    }

    View full-size slide

  13. ΦϓγϣφϧܕͷnilνΣοΫ
    Ͳ͏͢Δʁ
    if let _ = optionalObject {
    }
    if optionalObject != nil {
    }

    View full-size slide

  14. [weak self]ͷguard letͷself
    Ͳ͏͢Δʁ
    guard let `self` = self else { return }
    guard let wSelf = self else { return }
    guard let me = self else { return }

    View full-size slide

  15. [weak self]ͷguard letͷself
    Ͳ͏͢Δʁ
    guard let `self` = self else { return }
    guard let wSelf = self else { return }
    guard let me = self else { return }

    View full-size slide

  16. ܕਪ࿦Ͳ͏͢Δʁ
    // Good
    let title = “Tapple”
    // Bad
    let title: String = “Tapple”
    // Good
    let groups = [String]()
    // Bad
    let groups: [String] = []
    let groups: [String] = [String]()
    // Good
    let score = CGFloat(0)
    // Bad
    let score: CGFloat = 0
    ࢖͏ʂ

    View full-size slide

  17. array/dictionary͸ܕΛॻ͍ͨํ͕

    Ϗϧυ͕ૣ͍Β͍͔͠Β͠·ͤΜ͔ʁ
    ͦ͏͠Α͏ʂ
    // Good
    let title = “Tapple”
    // Bad
    let title: String = “Tapple”
    // Good
    let score = CGFloat(0)
    // Bad
    let score: CGFloat = 0
    // Good
    let groups = [String]()
    // Bad
    let groups: [String] = []
    let groups: [String] = [String]()
    array/dictionary͸ܕਪ࿦͠ͳ͍

    View full-size slide

  18. IBOutletͷม਺ʹ֎͔ΒΞΫηε͠ͳ͍ͱ͖
    ͸fileprivate͚ͭͨํ͕ྑ͘ͳ͍ʁ
    @IBOutlet fileprivate weak var title: UILabel!
    @IBOutlet weak var title: UILabel?
    - ͚ͭΔ
    - ଞͷΫϥε͔Βࢀর͢Δͱ͖͸ʁʹ͢Δ
    swift4Ͱprivateͷڍಈ͕มΘͬͨͷͰ
    ͜͜͸privateʹͳΓ·ͨ͠

    View full-size slide

  19. ϓϩτίϧͷ࣮૷͸ผʑͷextension
    ʹ͠ͳ͍ʁ
    ͢Δ
    - ؔ࿈ϝιουͷՄಡੑͱϓϩτίϧ௥Ճͷ༰қ͞޲্ͷͨΊ
    - UITableViewDataSourceUITableViewDelegate΋όϥόϥ

    View full-size slide

  20. ໌ࣔతʹselfΛॻ͘ʁ
    - Ϋϩʔδϟʔ಺΍ύϥϝʔλͷিಥ͕͋Δͱ͖͚ͩ
    -Ϋϩʔδϟʔʹ͓͚ΔselfͷΩϟϓνϟϦϯά໨ཱ
    - ৑௕͕͞ແ͘ͳΔ
    ॻ͔ͳ͍ʂ

    View full-size slide

  21. ܧঝ͠ͳ͍Ϋϥεʹ͸final͚ͭͨํ͕
    ྑ͘ͳ͍ʁ
    - ܧঝͷਖ਼౰ͳඞཁੑ͕͋Δ৔߹ʹͷΈ͚ͭͳͯ͘΋ྑ͍
    ͚ͭΔʂ

    View full-size slide

  22. String΁ͷΩϟετͲ͏͠·͢ʁ
    return "\(score)"
    return String(score)

    View full-size slide

  23. String΁ͷΩϟετͲ͏͠·͢ʁ
    return "\(score)"
    return String(score)

    View full-size slide

  24. ίʔσΟϯάن໿
    - ίʔυʹ౷Ұײ͕ͰΔ
    - ৽͘͠JOINͨ͠ਓ͕ࠔΒͳ͍
    - ٞ࿦͕͠΍͍͢νʔϜʹͳͬͨ

    View full-size slide

  25. Architecture

    View full-size slide

  26. - Flux
    - CleanArchitecture
    Architecture

    View full-size slide

  27. Guide to App Architecture
    Google Developers : https://developer.android.com/topic/libraries/architecture/guide.html

    View full-size slide

  28. MVVM + Repositoryύλʔϯ
    Architecture

    View full-size slide

  29. https://github.com/ssk5460/SwiftMVVMRepositoryPatternSample
    Github

    View full-size slide

  30. MainViewController DetailViewController
    Mobile
    Data
    UserRepository
    update data
    observe/notify

    View full-size slide

  31. UserRepositoryʹ͍ͭͯ
    final class UserRepository {
    static let shared = UserRepository()
    private let apiClient: ApiClientType
    private let bag = DisposeBag()
    let updatedUser: Observable
    private let _updatedUser = PublishSubject()
    init(apiClient: ApiClientType = UserApiClientMock()) {
    self.apiClient = apiClient
    self.updatedUser = _updatedUser
    }
    func updateUser(user: UserEntity) -> Observable {
    return apiClient.updateUser(user)
    .do(onNext: { [weak self] in
    self?._updatedUser.onNext($0)
    })
    .flatMap { _ in Observable.empty() }
    .catchError { .just($0) }
    }
    }
    7JFX.PEFM͸͜ΕΛ؂ࢹ

    View full-size slide