-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to call @available? #111
Comments
Your question is a little off topic from this repo but I don't know of much better place. The Swift I think the best way to emulate this type of thing is to use the let s = System::new();
if(s.os_version().starts_with("11.0")) { // for macOS
// whatever
} The implementation for You may also use the |
@simlay Thank you for your reply. I agree, it's a bit off topic but wasn't sure where to ask. I could be wrong, but I believe The sysinfo crate would be a last resort. I'd like to tap into the same thing |
Hmm. The docks from clang: https://clang.llvm.org/docs/LanguageExtensions.html#objective-c-available
This implies that it may actually do the check for you at runtime. I'm not sure how to send that to the objective-c runtime. @madsmtm has been doing some interesting work on |
However, https://godbolt.org/z/s8Gzx3hME, this seems to indicate that it's compile time if I am reading the assembly right |
I am working on a crate to help do this in Rust, as it would be beneficial for a few things only available in newer versions, namely certain optimizations, linking to frameworks and some C symbols. However, it'll probably take a while before it is done, so I would recommend the |
@madsmtm I'd like to be able to do runtime checks as well. Something like from https://nshipster.com/available/: @available(iOS 13.0, *)
final class CustomCompositionalLayout: UICollectionViewCompositionalLayout { … }
func createLayout() -> UICollectionViewLayout {
if #available(iOS 13, *) { // runtime check!
return CustomCompositionalLayout()
} else {
return UICollectionViewFlowLayout()
}
} I'm not familiar with Swift (or low level stuff) enough to know how exactly that works. Is it dynamic linking or something? Is that possible now in Rust? If not, would the crate you are making be able to do runtime checks as well? |
Actually it's a little more complex than I thought: Objective-C's As an example, if you have the following Objective-C code: if (@available(macOS 10.10, *)) {
printf("Hello, macOS > 10.10!\n");
}
if (@available(macOS 10.14, *)) {
printf("Hello, macOS > 10.14!\n");
} And tell Check out a tweaked version of your godbolt example, where we set |
But again, using the |
How would I do this in rust?
The text was updated successfully, but these errors were encountered: