SlideShare a Scribd company logo
最佳实践的开始
寻找更优的实现
最佳实践包含哪些
解决什么问题
适用什么场景
解决的⽅方式
这样实践的好处
实例
分享三个实践

Objective C ARC
Light View Controller
Ways to avoid/find bug
ARC Best Practices
http:/
/amattn.com/2011/12/07/arc_best_practices.html

General : property definitions
Bridging : CFxxx -> NSxxx
Out parameters : NSError
Block : weak or strong
Accessing CGThings from NSThings or
UIThings
Light View Controller
http:/
/www.objc.io/issue-1/lighter-view-controllers.html

Move Domain Logic into the Model
Move View Code into the View Layer
Separate Out Data Source and Other Protocols
Creating the Store Class
Move Web Service Logic to the Model Layer
Communication
Ways to avoid/find bug
Use assert to check unexpected situation
Unit test

Logging

Cost

App Testing

100
75
50
25
0
Assert UT Test Log Crash

Crash report
Misc
Instrument
Lint tools

Hour

180
135
90
45
0
Assert UT

Test

Log Crash
Use Assert to check Parameter
- (BOOL)appendPartWithFileURL:(NSURL *)fileURL
name:(NSString *)name
fileName:(NSString *)fileName
mimeType:(NSString *)mimeType
error:(NSError * __autoreleasing *)error
{
NSParameterAssert(fileURL);
NSParameterAssert(name);
NSParameterAssert(fileName);
NSParameterAssert(mimeType);

Check required resource
#if DEBUG
NSString *mainBundlePath = [[NSBundle mainBundle] resourcePath];
NSString *path = [mainBundlePath stringByAppendingPathComponent:kDOUADStandardResourceBundle];
NSAssert([NSBundle bundleWithPath:path] != nil,
[@"Need" stringByAppendingPathComponent:kDOUADStandardResourceBundle]);
path = [mainBundlePath stringByAppendingPathComponent:kDOUADCustomResourceBundle];
NSAssert([NSBundle bundleWithPath:path] != nil,
[@"Need" stringByAppendingPathComponent:kDOUADCustomResourceBundle]);
#endif

User assert to check expected value
BOOL existed = [[NSFileManager defaultManager] fileExistsAtPath:dir isDirectory:&isDir];
NSAssert(existed == NO || isDir == YES, @"Should be directory");
Assert vs try-catch
Try... catch - for exceptional
conditions
Assertions for catching invalid
code
Unit Test & Code quality
Unit test Examples:
DOUUserManager
AmonSulIOS

What we can do?
More unit test in common library
Test invisible logic
Logging
logging error, warning, etc properly
Check logging message after QA test

Crash report
Check crash report daily

Misc
Run analysis

More Related Content

Similar to 推荐 iOS 开发的几个最佳实践

Coldbox developer training – session 4
Coldbox developer training – session 4Coldbox developer training – session 4
Coldbox developer training – session 4
Billie Berzinskas
 
cupdf.com_chapter-11-system-level-verification-issues-the-importance-of-verif...
cupdf.com_chapter-11-system-level-verification-issues-the-importance-of-verif...cupdf.com_chapter-11-system-level-verification-issues-the-importance-of-verif...
cupdf.com_chapter-11-system-level-verification-issues-the-importance-of-verif...
SamHoney6
 
Advancing VLSI Design Reliability: A Comprehensive Examination of Embedded De...
Advancing VLSI Design Reliability: A Comprehensive Examination of Embedded De...Advancing VLSI Design Reliability: A Comprehensive Examination of Embedded De...
Advancing VLSI Design Reliability: A Comprehensive Examination of Embedded De...
IRJET Journal
 
Tdd,Ioc
Tdd,IocTdd,Ioc
Chameleon Model
Chameleon ModelChameleon Model
Chameleon Model
Rohan Kachewar
 
Automated Formal Verification of SystemC/C++ High-Level Synthesis Models
Automated Formal Verification of SystemC/C++ High-Level Synthesis ModelsAutomated Formal Verification of SystemC/C++ High-Level Synthesis Models
Automated Formal Verification of SystemC/C++ High-Level Synthesis Models
Sergio Marchese
 
Spring boot microservice metrics monitoring
Spring boot   microservice metrics monitoringSpring boot   microservice metrics monitoring
Spring boot microservice metrics monitoring
Oracle Korea
 
Spring Boot - Microservice Metrics Monitoring
Spring Boot - Microservice Metrics MonitoringSpring Boot - Microservice Metrics Monitoring
Spring Boot - Microservice Metrics Monitoring
DonghuKIM2
 
Assignment Grading Rubric Course IT286 Unit 4 Po.docx
Assignment Grading Rubric  Course IT286   Unit 4    Po.docxAssignment Grading Rubric  Course IT286   Unit 4    Po.docx
Assignment Grading Rubric Course IT286 Unit 4 Po.docx
ssuser562afc1
 
4.9.a apend tuning and performance
4.9.a apend tuning and performance4.9.a apend tuning and performance
4.9.a apend tuning and performance
Acácio Oliveira
 
Lo 09
Lo 09Lo 09
Lo 09
liankei
 
Brian cerny
Brian cernyBrian cerny
Brian cerny
bricer1272
 
Quantstamp Report - LINKSWAP
Quantstamp Report - LINKSWAPQuantstamp Report - LINKSWAP
Quantstamp Report - LINKSWAP
Roy Blackstone
 
SQL Performance Tuning and New Features in Oracle 19c
SQL Performance Tuning and New Features in Oracle 19cSQL Performance Tuning and New Features in Oracle 19c
SQL Performance Tuning and New Features in Oracle 19c
RachelBarker26
 
A Test Automation Framework
A Test Automation FrameworkA Test Automation Framework
A Test Automation Framework
Gregory Solovey
 
To study pcms pegasus erp cargo management system-release-7 from architectu...
To study pcms   pegasus erp cargo management system-release-7 from architectu...To study pcms   pegasus erp cargo management system-release-7 from architectu...
To study pcms pegasus erp cargo management system-release-7 from architectu...
Shahzad
 
Microservices With Istio Service Mesh
Microservices With Istio Service MeshMicroservices With Istio Service Mesh
Microservices With Istio Service Mesh
Natanael Fonseca
 
System verilog important
System verilog importantSystem verilog important
System verilog important
elumalai7
 
What are Software Testing Methodologies | Software Testing Techniques | Edureka
What are Software Testing Methodologies | Software Testing Techniques | EdurekaWhat are Software Testing Methodologies | Software Testing Techniques | Edureka
What are Software Testing Methodologies | Software Testing Techniques | Edureka
Edureka!
 
04+ECETEMT092-+WDT+APB+UVM.pdf
04+ECETEMT092-+WDT+APB+UVM.pdf04+ECETEMT092-+WDT+APB+UVM.pdf
04+ECETEMT092-+WDT+APB+UVM.pdf
SamHoney6
 

Similar to 推荐 iOS 开发的几个最佳实践 (20)

Coldbox developer training – session 4
Coldbox developer training – session 4Coldbox developer training – session 4
Coldbox developer training – session 4
 
cupdf.com_chapter-11-system-level-verification-issues-the-importance-of-verif...
cupdf.com_chapter-11-system-level-verification-issues-the-importance-of-verif...cupdf.com_chapter-11-system-level-verification-issues-the-importance-of-verif...
cupdf.com_chapter-11-system-level-verification-issues-the-importance-of-verif...
 
Advancing VLSI Design Reliability: A Comprehensive Examination of Embedded De...
Advancing VLSI Design Reliability: A Comprehensive Examination of Embedded De...Advancing VLSI Design Reliability: A Comprehensive Examination of Embedded De...
Advancing VLSI Design Reliability: A Comprehensive Examination of Embedded De...
 
Tdd,Ioc
Tdd,IocTdd,Ioc
Tdd,Ioc
 
Chameleon Model
Chameleon ModelChameleon Model
Chameleon Model
 
Automated Formal Verification of SystemC/C++ High-Level Synthesis Models
Automated Formal Verification of SystemC/C++ High-Level Synthesis ModelsAutomated Formal Verification of SystemC/C++ High-Level Synthesis Models
Automated Formal Verification of SystemC/C++ High-Level Synthesis Models
 
Spring boot microservice metrics monitoring
Spring boot   microservice metrics monitoringSpring boot   microservice metrics monitoring
Spring boot microservice metrics monitoring
 
Spring Boot - Microservice Metrics Monitoring
Spring Boot - Microservice Metrics MonitoringSpring Boot - Microservice Metrics Monitoring
Spring Boot - Microservice Metrics Monitoring
 
Assignment Grading Rubric Course IT286 Unit 4 Po.docx
Assignment Grading Rubric  Course IT286   Unit 4    Po.docxAssignment Grading Rubric  Course IT286   Unit 4    Po.docx
Assignment Grading Rubric Course IT286 Unit 4 Po.docx
 
4.9.a apend tuning and performance
4.9.a apend tuning and performance4.9.a apend tuning and performance
4.9.a apend tuning and performance
 
Lo 09
Lo 09Lo 09
Lo 09
 
Brian cerny
Brian cernyBrian cerny
Brian cerny
 
Quantstamp Report - LINKSWAP
Quantstamp Report - LINKSWAPQuantstamp Report - LINKSWAP
Quantstamp Report - LINKSWAP
 
SQL Performance Tuning and New Features in Oracle 19c
SQL Performance Tuning and New Features in Oracle 19cSQL Performance Tuning and New Features in Oracle 19c
SQL Performance Tuning and New Features in Oracle 19c
 
A Test Automation Framework
A Test Automation FrameworkA Test Automation Framework
A Test Automation Framework
 
To study pcms pegasus erp cargo management system-release-7 from architectu...
To study pcms   pegasus erp cargo management system-release-7 from architectu...To study pcms   pegasus erp cargo management system-release-7 from architectu...
To study pcms pegasus erp cargo management system-release-7 from architectu...
 
Microservices With Istio Service Mesh
Microservices With Istio Service MeshMicroservices With Istio Service Mesh
Microservices With Istio Service Mesh
 
System verilog important
System verilog importantSystem verilog important
System verilog important
 
What are Software Testing Methodologies | Software Testing Techniques | Edureka
What are Software Testing Methodologies | Software Testing Techniques | EdurekaWhat are Software Testing Methodologies | Software Testing Techniques | Edureka
What are Software Testing Methodologies | Software Testing Techniques | Edureka
 
04+ECETEMT092-+WDT+APB+UVM.pdf
04+ECETEMT092-+WDT+APB+UVM.pdf04+ECETEMT092-+WDT+APB+UVM.pdf
04+ECETEMT092-+WDT+APB+UVM.pdf
 

Recently uploaded

Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Wask
 
Operating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptxOperating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptx
Pravash Chandra Das
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!
GDSC PJATK
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Azure API Management to expose backend services securely
Azure API Management to expose backend services securelyAzure API Management to expose backend services securely
Azure API Management to expose backend services securely
Dinusha Kumarasiri
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Tatiana Kojar
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Jeffrey Haguewood
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Postman
 

Recently uploaded (20)

Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
 
Operating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptxOperating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptx
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Azure API Management to expose backend services securely
Azure API Management to expose backend services securelyAzure API Management to expose backend services securely
Azure API Management to expose backend services securely
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
 

推荐 iOS 开发的几个最佳实践

  • 3. 分享三个实践 Objective C ARC Light View Controller Ways to avoid/find bug
  • 4. ARC Best Practices http:/ /amattn.com/2011/12/07/arc_best_practices.html General : property definitions Bridging : CFxxx -> NSxxx Out parameters : NSError Block : weak or strong Accessing CGThings from NSThings or UIThings
  • 5. Light View Controller http:/ /www.objc.io/issue-1/lighter-view-controllers.html Move Domain Logic into the Model Move View Code into the View Layer Separate Out Data Source and Other Protocols Creating the Store Class Move Web Service Logic to the Model Layer Communication
  • 6. Ways to avoid/find bug Use assert to check unexpected situation Unit test Logging Cost App Testing 100 75 50 25 0 Assert UT Test Log Crash Crash report Misc Instrument Lint tools Hour 180 135 90 45 0 Assert UT Test Log Crash
  • 7. Use Assert to check Parameter - (BOOL)appendPartWithFileURL:(NSURL *)fileURL name:(NSString *)name fileName:(NSString *)fileName mimeType:(NSString *)mimeType error:(NSError * __autoreleasing *)error { NSParameterAssert(fileURL); NSParameterAssert(name); NSParameterAssert(fileName); NSParameterAssert(mimeType); Check required resource #if DEBUG NSString *mainBundlePath = [[NSBundle mainBundle] resourcePath]; NSString *path = [mainBundlePath stringByAppendingPathComponent:kDOUADStandardResourceBundle]; NSAssert([NSBundle bundleWithPath:path] != nil, [@"Need" stringByAppendingPathComponent:kDOUADStandardResourceBundle]); path = [mainBundlePath stringByAppendingPathComponent:kDOUADCustomResourceBundle]; NSAssert([NSBundle bundleWithPath:path] != nil, [@"Need" stringByAppendingPathComponent:kDOUADCustomResourceBundle]); #endif User assert to check expected value BOOL existed = [[NSFileManager defaultManager] fileExistsAtPath:dir isDirectory:&isDir]; NSAssert(existed == NO || isDir == YES, @"Should be directory");
  • 8. Assert vs try-catch Try... catch - for exceptional conditions Assertions for catching invalid code
  • 9. Unit Test & Code quality Unit test Examples: DOUUserManager AmonSulIOS What we can do? More unit test in common library Test invisible logic
  • 10. Logging logging error, warning, etc properly Check logging message after QA test Crash report Check crash report daily Misc Run analysis