目前分類:iOS (228)

瀏覽方式: 標題列表 簡短摘要

Activity Diagram.png

(UML活動圖)

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

 

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

Reason: 'A test configuration must be provided to _XCTestMain.'

截圖 2020-10-16 上午11.57.17

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

 Xcode SwiftUI Preview for ViewController's view (UIView subclass)

 

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

需裝 pod plugin
$ gem install cocoapods-binary
 

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

1.可以return擁有associatedtype的"實際"型別

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

extension UICollectionView {
    public func scrollToSection(section: Int, animated: Bool) {

        guard numberOfSections > section else {
            return
        }

        guard numberOfItems(inSection: section) > 0 else {
            return
        }

        let sectionY: CGFloat = { () -> CGFloat in

            let indexPath = IndexPath(item: 0, section: section)

            let top: CGFloat = 0

            guard let attributes = layoutAttributesForItem(at: indexPath) else {
                return top
            }

            switch attributes.representedElementCategory {
            case .cell, .decorationView:
                return top
                
            case .supplementaryView:
                guard let attributes = layoutAttributesForSupplementaryElement(ofKind: UICollectionView.elementKindSectionHeader, at: indexPath) else {
                    return top
                }

                return attributes.frame.origin.y
            @unknown default:
                return top
            }
        }()

        var offsetY: CGFloat = sectionY - contentInset.top

        if #available(iOS 11.0, *) {
            offsetY -= safeAreaInsets.top
        }

        let offset = CGPoint(x: 0, y: offsetY)
        setContentOffset(offset, animated: animated)
    }
}


避免不同Layout或是沒有header的時候,在iOS 10發生Crash

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


小賢 發表在 痞客邦 留言(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) 人氣()

在unit test 裡面會發現compile 會出現 Failled to import bridging header

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

iOS 9之後有新的方式可以改status bar
https://www.jianshu.com/p/9f7f3fa624e7

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

expr {{變數}} = {{想改的值}}

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

 

var str = "Hello, playground+"
var allowCharactoers = CharacterSet.urlQueryAllowed
allowCharactoers.remove(Unicode.Scalar("+"))

print(str.addingPercentEncoding(withAllowedCharacters: allowCharactoers))

 

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

問題:

螢幕快照 2018-04-19 上午10.25.35

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

在Xcode 9.2 升級到9.3的時候,模擬器可正常Build,但在實機上面發生了Compile error: abort trap: 6,弄了很久,最後把compile 不過的code包成 function就行了


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

想正確取得 button.titleLabel?.frame ,在設定完text後,需用button.setNeedsLayout()及button.layoutIfNeeded()

 

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

自己SubClass UIView,然後再對layer做Gradient

 

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