当前位置:网站首页>Swiftui swift internal skill: five skills of using opaque type in swift
Swiftui swift internal skill: five skills of using opaque type in swift
2022-07-07 11:45:00 【Knowledge fatness】
If you are Swift Novice , You may not be familiar with the concept of opaque types . In short , An opaque type is a type that cannot be subclassed or initialized from outside its definition module . let me put it another way , This is a way to hide implementation details from other parts of the code .
although opaque Type can be used for many purposes , But they are especially suitable for creating easy-to-use and difficult to misuse API. In this post , We will share in Swift Use in opaque Five skills of type .
1. Use opaque types to hide implementation details
One of the biggest benefits of using opaque types is that they allow you to hide implementation details from other parts of the code . When you want to create something that is easy to use and difficult to misuse API when , This is especially useful .
for example , Suppose you are creating a library that provides custom view controllers . You may want to hide the implementation details of the view controller from the users of the Library . By using opaque types , You can do this .
2. Use opaque types to enforce type safety
Another benefit of using opaque types is that they help you enforce type safety in your code . This is because opaque types cannot be subclassed or initialized from outside their definition module .
for example , Suppose you have a that returns an opaque type API. If you try to subclass or initialize the type from outside the definition module , You will receive compiler errors . This means that you can be sure that only the types you expect are used in your code .
3. Use opaque types to improve performance
In addition to helping hide implementation details and enforce type safety , Opaque types can also improve performance . This is because the compiler can optimize code that uses opaque types more effectively .
for example , Suppose you have a method that takes an opaque type as a parameter . The compiler can inline this method , For better performance .
4. Use opaque types to limit the visibility of types
Another advantage of using opaque types is that they help you limit the visibility of types . This is because opaque types can only be initialized from their definition modules .
When you want to create something for a specific group of people API when , It would be very helpful . for example , Suppose you
边栏推荐
- 0.96 inch IIC LCD driver based on stc8g1k08
- 核舟记(一):当“男妈妈”走进现实,生物科技革命能解放女性吗?
- MySQL安装常见报错处理大全
- . Net Maui performance improvement
- 千人规模互联网公司研发效能成功之路
- R語言使用magick包的image_mosaic函數和image_flatten函數把多張圖片堆疊在一起形成堆疊組合圖像(Stack layers on top of each other)
- 【纹理特征提取】基于matlab局部二值模式LBP图像纹理特征提取【含Matlab源码 1931期】
- The road to success in R & D efficiency of 1000 person Internet companies
- ‘module‘ object is not callable错误
- 关于在云服务器上(这里用腾讯云)安装mysql8.0并使本地可以远程连接的方法
猜你喜欢
Onedns helps college industry network security
Some opinions and code implementation of Siou loss: more powerful learning for bounding box regression zhora gevorgyan
In my limited software testing experience, a full-time summary of automation testing experience
How much do you know about excel formula?
electron添加SQLite数据库
Electron adding SQLite database
关于测试人生的一站式发展建议
LeetCode - 面试题17.24 最大子矩阵
Talk about SOC startup (x) kernel startup pilot knowledge
正在運行的Kubernetes集群想要調整Pod的網段地址
随机推荐
R語言使用magick包的image_mosaic函數和image_flatten函數把多張圖片堆疊在一起形成堆疊組合圖像(Stack layers on top of each other)
STM32F1与STM32CubeIDE编程实例-MAX7219驱动8位7段数码管(基于SPI)
Suggestions on one-stop development of testing life
Talk about SOC startup (11) kernel initialization
Talk about SOC startup (IX) adding a new board to uboot
Cmu15445 (fall 2019) project 2 - hash table details
Programming examples of stm32f1 and stm32subeide -315m super regenerative wireless remote control module drive
关于SIoU《SIoU Loss: More Powerful Learning for Bounding Box Regression Zhora Gevorgyan 》的一些看法及代码实现
总结了200道经典的机器学习面试题(附参考答案)
sink 消费 到 MySQL, 数据库表里面已经设置了 自增主键, flink 里面,如何 操作?
竟然有一半的人不知道 for 与 foreach 的区别???
对比学习之 Unsupervised Learning of Visual Features by Contrasting Cluster Assignments
深度学习秋招面试题集锦(一)
R language Visual facet chart, hypothesis test, multivariable grouping t-test, visual multivariable grouping faceting boxplot, and add significance levels and jitter points
Blog moved to Zhihu
Software design - "high cohesion and low coupling"
正在運行的Kubernetes集群想要調整Pod的網段地址
Network protocol concept
Internet Protocol
Case study of Jinshan API translation function based on retrofit framework