question In OC, enum can have multiple selections. For example:
By combining two enum values with |, you can achieve the effect of multiple selection. Now the question is: how to achieve the same effect in Swift? Option Type in Swift Swift's enum does not support multiple selections, so the option type that supports multiple selections should be implemented using struct: RawOptionSet. To implement the options type yourself, you can refer to this answer. The official SDK is ported using this method. Correct way to write The correct way to write the code in the above example using Swift is as follows:
In OS X 10.10, this works. iOS SDK bugs But in the current version of iOS 8 SDK, this way of writing cannot be compiled. This is because in the iOS 8 SDK, NSStringDrawingOptions has been transplanted to enum: Int instead of struct: RawOptionSet. How to solve this problem? We can only use OC to workaround. Solution Because the options used are the same, I simply wrote this class: OCUtils.h
OCUtils.m
Add the following to Bridging-Header.h:
Swift files used
If there are further requirements, it can be changed to be more general. The overall principle can only be like this. Reference for this article : How to pass multiple enum values as a function parameter Original article: Swift's pitfall: How to implement multiple selection of enum |
<<: CES2015: ZTE releases 6-inch ultra-large screen mobile phone Grand X Max+
>>: Break the 24-hour unspoken rule and create truly innovative apps
Ride-hailing app Uber announced yesterday that it...
When it comes to Tik Tok live streaming , the mos...
Missing you is a pain that breathes, it lives in ...
In November 2020, more than 240 Late Cretaceous d...
When a friend is deleted from WeChat, you will no...
Today is Frost Descent, the eighteenth of the twe...
Du Xiangwan, 83 years old this year He is an acad...
Dang Xing Xue Tang: Amateurs can also become popu...
Recently, the well-known online data management we...
I have interviewed many people in the past year. ...
Many friends who work in P2P would say that there...
Everything will be reset to zero. With the openin...
Some of these phones you remember, and may have e...
[[142068]] Preface As mentioned in the previous a...
1. There is a very famous marginal effect in econ...