小賢 發表在 痞客邦 留言(0) 人氣()

import UIKit

 

小賢 發表在 痞客邦 留言(0) 人氣()

只跑一次的Globa function:

/// Run once after delay if no be called
///
/// - Parameters:
///   - delay: delay time
///   - saveCurrent: should put it to 'property scope'
///   - getCurrent: should pass 'weak' self property
///   - once: do once closure
func runOnce(delay: TimeInterval,
                saveCurrent: inout DispatchTime?,
                getCurrent: @autoclosure @escaping () -> DispatchTime?,
                once: @escaping () -> Void)
{
    let begin: DispatchTime = DispatchTime.now()
    saveCurrent = begin
    
    DispatchQueue.main.asyncAfter(deadline: begin + delay) {
        
        guard let current = getCurrent(), current == begin else {
            print("Ignore because still be called")
            return
        }
        
        print("Run once")
        once()
    }
}

 

Caller端用法:

小賢 發表在 痞客邦 留言(0) 人氣()

protocol OrderPickUpViewModelFactoryProtocol {
    
}

extension OrderPickUpViewModelFactoryProtocol {
    
    fileprivate typealias TResult = OrderPickUpCellViewModelUpProtocol
    
    fileprivate func createRows(info: OrderDetailModel.ShuttleInfo, _: TDesc.Type, _: TLocation.Type, _: TSubDetail.Type, _: TTitle.Type) -> [TResult]
        where TDesc: OrderPickUpDetailDescCellViewModelProtocol,
        TLocation: OrderPickUpDetaiLocationCellViewModelProtocol,
        TSubDetail: OrderPickUpDetailSubDetailCellViewModelProtocol,
        TTitle: OrderPickUpDetailTitleCellViewModelProtocol
    {
        
        var rows: [TResult?] = []
        
        rows.append(TTitle(titleText: "AAA")))
        rows.append(TLocation(titleText: "BBB"))
        // .....        

        return rows.dropNil
    }
}

1.在工廠extension 內預設實作商業邏輯

 

小賢 發表在 痞客邦 留言(0) 人氣()

Label 設定AttributedText後,需重新指定LineBreakMode

titleLabel.attributedText = NSMutableAttributedString(string: viewModel.model.title, attributes: titleAttributes)

小賢 發表在 痞客邦 留言(0) 人氣()