I'm wanting to write some compile-time code (i.e. code that is run when the project is compiled). This is used in other languages (e.g. Java) to write code generators (e.g. Dagger 2).
Is this possible in Swift? If so how? It is rather important for what I'm attempting to do.
Your question is very vague. There are multiple reasons for writing compile-time code, and it all depends on what you want to do.
If you want to write conditional code that only runs based on certain compile-time directives, use
#if build configuration
statements
#else
statements
#endif
If you want to generate code like a preprocessor would do in macros to reduce code duplication, then you should simply change your mindset and use swift functions and generics that will achieve the same result, only better. (Simple macros like #define xxx ... are replaced by let xxx = ...).
Finally, if you want to generate huge amounts of code then Swift isn't the language for you, you should use a dedicated code generator or some scripting language. For example, if you're looking to generate code for a state machine, use dedicated tools for that task that take as input UML. Obviously you'll have a hard time today finding tools that output Swift code (least of which being that Swift itself is a moving target), but that'll change over time.
Related
I wrote my own ORM framework (something along the lines of CoreData or Realm), and also wrote quite a few tests in Xcode for it.
Now I want to introduce an additional encoding format used for storing data on disk, but I also want to keep supporting the original encoding format.
Is there a good strategy to run my all my existing -test* methods for both encoding formats without duplicating the existing test code?
The easiest way I have found is to just create a new test target and add all the same test classes to it. If you want them run in one go, create a target that has both of these test targets as dependencies (or just runs them manually).
How you parametrize for your different targets is up to you, we've successfully used two implementations of a category that has the definition that varies.
I'd like to convert a CMake-based C++ library to bazel.
As part of the current CMake project, I'm using a libclang-based code generator that parses C++ headers and generates C++ code from the parsed AST. In order to do that, I need the actual compiler flags used to build the cc_library the header is part of. The flags are passed to the code generation tool so it can use clang's preprocessor.
Is there any way I could access the compiler flags used to build a dependency from a skylark- or gen_rule rule? I'm particularly interested in the include paths and defines.
We're working on it. Well, not right now, but will soon. You might want to subscribe to the corresponding issue, and maybe describe your requirements there so we take them into account when designing the API.
In Java, we can build up expressions to be called using ScriptEngine. This is nice for building up frameworks based on a common naming convention. In JavaScript, there is of course eval(). Does Swift have some sort of mechanism for evaluating a string which contains a swift expression? I'm aware that this could be potentially abused; however, it would simplify my present development.
No. Swift is a compiled language, and the runtime doesn't include the compiler. The iOS SDK doesn't provide a way to evaluate run-time Swift code.
You can execute JavaScript using JavaScriptCore, and JavaScriptCore makes it pretty easy to expose Swift objects and functions to the script. Maybe that will help you.
Hi, I'm just wondering how you could obfuscate functions in iOS binary?
If you tried to reverse iOS binaries using tools like ida you will see part of the binaries have obfuscated functions like all or partly named sub_xxxxxxxx but the other have human readable functions
Someone said, add those lines to the top of your header without any further explaining:
#define SecurityClass ah7p
#define checkCopyProtection xcyc
What the methods used to secure your App?
Sorry for the dumb question, but I'm new there and I ended up with no answer explained what I need.
There are a couple of ways to obfuscate an iOS binary.
Open Source compiler named llvm-obfuscate (https://github.com/obfuscator-llvm/obfuscator/wiki) It has some nice features to obfuscate during compilation. You are replacing your default compiler with that one.
There are for Windows of course VMWare oder Themdia that can post process but that is not the case.
Besides that I just know one more which is Liasoft antispy. It is a very advanced anti analysis toolkit that allows you to encrypt functions and much more during compilation using mixed Objective-C and C++ code. ( https://www.liasoft.de/en/products/antispy/ )
Not sure if one of these is the right one for you. Except these things you are pretty lost since Objective-C is a compiled language with lots of metadata.
Hope I could help you, this is my first post.
If you only care about obfuscating method names then the easiest way is to write relevant parts of your application in C or C++. For instance, you can rewrite your SecurityClass as a C++ class instead of Objective-C class. This will not make your code reverse-engineering-proof, but it will at least raise the bar a bit. (NOTE: I'm not saying this is the right thing to do from software engineering point of view, though).
If you need to obfuscate code, then you are in a search for a tool that can do this. There are several such tools, both commercial and free. One project for doing exactly this is obfuscator-llvm.
I need to get the clipboard into string,
After I getting the string of the clipboard I want to set the clipboard to something else.
Love2D doesn't have functions for accessing clip-board data. It's too platform-specific for it.
One of the strongest points of Lua is its ability to interface easily with C and C++ libraries through bindings. What you would have to do here is to write your own library in C (or find an existing one) that does what you want to do, write a binding for it for Lua and then use it from your love2d code.
Unfortunately, like Nicol said, this is likely going to be platform specific which means you'll need to write a library for each platform you want your game to run on and then use the love._os field to split your game logic.