吴建军-移动端开发中代码重构及架构优化

移动端开发中代码重构及架构优化
展开查看详情

1.iOS @ Keep

2.

3.

4.
 


5. 
 
 
 


6.

7.

8.

9. 
 
 
 
 
 
 


10. 0.22% 0.22% 0.19% 0.165% 0.14% 0.11% 0.1% 0.08% 0.055% 0% April May June July Aug

11.

12.warning error

13.struct User { public var name: String // ... init(name: String) { self.name = name } } func createUser(name: String) -> User { if (name.count < 6) { assert(false, "user name should at least 6 letters") return User(name: ""); } // initial user related resources // ... ... return User(name: name) }

14.- (void)test_recorder_write_record { [[ProfilerRecorder sharedLogger] startRecording]; [[ProfilerRecorder sharedLogger] record:self.sample.sample]; [[ProfilerRecorder sharedLogger] record:self.sample.sample]; NSArray <NSString *> *filesToUpload = [[ProfilerRecorder sharedLogger] rollFileAndFetchFilesDesc]; NSInteger size = [NSData dataWithContentsOfFile:filesToUpload.firstObject].length; XCTAssert(size == self.sample.sizeWithNewLine * 2); [[ProfilerRecorder sharedLogger] finish]; }

15.

16.
 


17.

18.


19.

20.

21.

22.

23.
 


24.

25.

26. BaseEntryCell PicTextEntryCell IEntryCell MusicContentCell VideoContentCell EntryCell …

27.class func reuseIdentifier(by model: TimeLineModel?) -> String? { var mask = EntryCellResuseMaskNone as? EntryCellResuseMask if EntryMultiPhotosView.shouldDisplay(forData: model) { if let aMask = mask { mask = aMask | EntryCellResuseMaskPhotos } } if model?.sampleComments.count ?? 0 > 0 { if let aMask = mask { mask = aMask | EntryCellResuseMaskSamples } } if model?.content.length ?? 0 > 0 { if let aMask = mask { mask = aMask | EntryCellResuseMaskText } } // … … return self.reuseID(by: mask) }

28.func updateData(_ model: TimeLineModel?) { timelineModel = model contentView.frame = CGRect(x: 0, y: 0, width: ScreenSize.width, height: 0) let originY: CGFloat = 0 if needHeaderView() { if headerView.superview == nil { contentView.addSubview(headerView) } headerView.updateData(model) } if needPhotoView() { if photoView.superview == nil { contentView.addSubview(photoView) } photoView.updateData(model) } if needShowSampleCommentsView() { if sampleCommentsView.superview == nil { contentView.addSubview(sampleCommentsView) } sampleCommentsView.updateData(model) } // … … }

29.