Skip to content

Commit

Permalink
feat: move extension to Core(#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
akrudal committed Jan 20, 2024
1 parent 97ea065 commit 38a9ac2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,26 +78,6 @@ final class HomeFamilyViewController: BaseViewController<HomeFamilyViewReactor>
}
}

extension Array {
init(with element: Element) {
self = [element]
}
}

protocol ItemIndexable {
associatedtype Item

subscript(indexPath: IndexPath) -> Item { get set }
}

extension ItemIndexable {
func item(at index: IndexPath) throws -> Item { self[index] }
func items(at indexes: [IndexPath]) throws -> [Item] { try indexes.map(self.item(at:)) }
}

extension TableViewSectionedDataSource: ItemIndexable { }
extension CollectionViewSectionedDataSource: ItemIndexable { }

extension HomeFamilyViewController {
private func bindInput(reactor: HomeFamilyViewReactor) {
familyCollectionView.rx.setDelegate(self)
Expand Down
23 changes: 23 additions & 0 deletions 14th-team5-iOS/Core/Sources/Common/Protocol/ItemIndexable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// ItemIndexable.swift
// Core
//
// Created by 마경미 on 20.01.24.
//

import UIKit
import RxDataSources

public protocol ItemIndexable {
associatedtype Item

subscript(indexPath: IndexPath) -> Item { get set }
}

extension ItemIndexable {
public func item(at index: IndexPath) throws -> Item { self[index] }
public func items(at indexes: [IndexPath]) throws -> [Item] { try indexes.map(self.item(at:)) }
}

extension TableViewSectionedDataSource: ItemIndexable { }
extension CollectionViewSectionedDataSource: ItemIndexable { }
14 changes: 14 additions & 0 deletions 14th-team5-iOS/Core/Sources/Extensions/Array+Ext.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// Array+Ext.swift
// Core
//
// Created by 마경미 on 20.01.24.
//

import Foundation

extension Array {
public init(with element: Element) {
self = [element]
}
}

0 comments on commit 38a9ac2

Please sign in to comment.