(UML活動圖)
目前分類:iOS (228)
- May 06 Thu 2021 19:34
[Swift] Mock Server
- Jan 17 Sun 2021 22:18
[Swift] Mock ViewModel for SwiftUI preview
- Oct 16 Fri 2020 11:56
[Xcode] UITest Runtime crash
Reason: 'A test configuration must be provided to _XCTestMain.'
- Aug 14 Fri 2020 23:55
[Xcode] SwiftUI Preview(真‧Design time sample data)
- Aug 02 Sun 2020 23:08
[Xcode] Cocoapods-binary plugin 加速30% build time
需裝 pod plugin
$ gem install cocoapods-binary
- Nov 21 Thu 2019 23:53
[Swift 5.1] `some` return type (Opaque Return Types)
1.可以return擁有associatedtype的"實際"型別
- Aug 26 Mon 2019 09:24
[Swift] CollectionView scroll to header
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
- Aug 15 Thu 2019 04:14
[Swift] 不同預設實作
- Jul 16 Tue 2019 18:02
[Swift] 忘記加rawValue 的....保護措拖
- Apr 11 Thu 2019 17:43
[Swift] 會call很多次,但只要最後一次
只跑一次的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端用法:
- Mar 25 Mon 2019 10:14
[Swift] 泛型抽象工廠
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 內預設實作商業邏輯
- Mar 08 Fri 2019 17:58
[Swift] TruncatingTail不見
Label 設定AttributedText後,需重新指定LineBreakMode
titleLabel.attributedText = NSMutableAttributedString(string: viewModel.model.title, attributes: titleAttributes)
- Mar 08 Fri 2019 14:47
[iOS] 解決UI / Unit test compile error
在unit test 裡面會發現compile 會出現 Failled to import bridging header
- Sep 17 Mon 2018 17:36
[iOS] iOS9之後有新的方式可以改status bar
iOS 9之後有新的方式可以改status bar
https://www.jianshu.com/p/9f7f3fa624e7
- Aug 01 Wed 2018 13:10
[iOS] LLDB 改runtime變數值
expr {{變數}} = {{想改的值}}
- Jul 09 Mon 2018 15:06
[Swift] 跳脫 + 字元
var str = "Hello, playground+" var allowCharactoers = CharacterSet.urlQueryAllowed allowCharactoers.remove(Unicode.Scalar("+")) print(str.addingPercentEncoding(withAllowedCharacters: allowCharactoers))
- Jun 06 Wed 2018 16:19
[iOS] 在模擬器略過 Undefined symbols for architecture x86_64
問題:
- May 12 Sat 2018 21:40
[iOS] Fix Xcode 9.3 abort trap: 6
在Xcode 9.2 升級到9.3的時候,模擬器可正常Build,但在實機上面發生了Compile error: abort trap: 6,弄了很久,最後把compile 不過的code包成 function就行了
- Mar 30 Fri 2018 10:00
[Swift] 取得正確 button.titleLabel?.frame
想正確取得 button.titleLabel?.frame ,在設定完text後,需用button.setNeedsLayout()及button.layoutIfNeeded()
- Mar 16 Fri 2018 12:07
[iOS] 解決Gradient layer frame 更新很慢