I want Swift to manage the framework loading of the framework.

Asked 2 years ago, Updated 2 years ago, 83 views

I am not sure if the title of the question is correct, so if there is a problem, please let me know.

I was creating an application on Swift, and I tried to improve performance using METAL.
It's working in itself, but on the other hand,
for devices that don't use METAL I'm having trouble dealing with it.

Originally, I created something that does not use METAL, so
If you can use METAL and if you can't use it,
I think it would be better if I could separate the correspondence, but I don't know how to deal with it.

For example, if you try to run it with a simulator (not METAL-enabled),

import Metal

A compiler error occurs at the .
I think it's because it's a compiler error, but the file you actually import runs
The error will stop occurring regardless of whether or not it is done.

On the other hand, if you try to run it on a non-METAL-capable product, the actual file you import will be
If you try not to run it, no errors will occur.

At the very least, I would like to be able to handle it on the actual machine, so please check the METAL support on the actual machine and
I wish I could control the loading of the METAL framework.
I'm imagining it, but I don't know how to do it.

If there is a good way, please let me know.
Thank you for your cooperation.

swift xcode6 framework

2022-09-29 21:20

2 Answers

I think you can use a macro branching method for each build target architecture.

#if!(arch(i386)||arch(x86_64)))
    // code device
    import Metal
#endif

Note that not only import but also API-enabled parts should not be built if the build target is a simulator.


2022-09-29 21:20

I'm sorry that I haven't been able to confirm it here, but the following settings may work.

Optional framework

Target General - Linked Framework and Librariesallows you to change the status of the framework, but if you set it to Optional, it will load the framework when you actually need it.

Link to a Library or Framework
https://developer.apple.com/library/mac/recipes/xcode_help-project_editor/Articles/AddingaLibrarytoaTarget.html


2022-09-29 21:20

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.