I was wondering if you can write inline assembly in Swift.
I know that in Objective-C you could use something like this:
inline void assemblyFunc() {
__asm__(/*Assembly*/);
}
But in Swift it seems that you can't use __asm__(/*Assembly*/).
Does anyone know how to use __asm__() if its even possible.
I haven't found anything about it, so I thought it would be a good question to ask.
There isn't a way in Swift itself. If you need this, probably a good opportunity to take advantage of Swift-ObjC interop.
To expand on what Robert Levy said, you can just use the Swift/Obj-C interop feature, and write an Obj-C class that does the ASM stuff, which you can then call from Swift.
It's an annoying workaround, but it should work nonetheless.
You can read more about how to do it [here]
Related
I am interested to learn more about the implementation details of class DispatchQueue : DispatchObject.
I have looked here, and here but I can't find the matching implementation.
You probably won't find this in the Swift code because it isn't Swift. This is just a front end for Cocoa's OS_dispatch_queue etc., which are not open source. It's not part of the Swift library; it's an iOS thing, not a language thing.
I am learning Swift by myself on MacOS. When following the tutorial and practicing the array function: <array_name>.sort(), I can get it executed but I always wonder how it works and what is the actual algorithm inside it.
So is there any way to check the certain function definitions?
If you want to check the declaration of the function/class, you can command-click on it. If you want the documentation, you can either option-click it or check it on the API reference page. If you want to see the implementation details of the Swift standard library, check the source code here at GitHub. If the implementation you are checking is in a non open-source APIs though, you can't quite check it.
This question already has answers here:
Custom NSLocalizedString?
(7 answers)
Closed 9 years ago.
This question is regarding the localization from inside the app.
There are several blogs/tutorials that really helps and show the way to do it.
The ones which i referred to implement it are as below:
http://learning-ios.blogspot.in/2011/04/advance-localization-in-ios-apps.html
http://www.pastie.org/1976594
I am able to achieve it (with the help of such blogs.. thanks to them).
But i was trying one thing and i had a little doubt regarding the same as below
I am trying to create a same macro as the NSLocalizedString
[i.e. NSString *NSLocalizedString(String *key, String *value)]
but with a different macro name
something like
[NSString *getLocalizedString(String *key, String *value)] in my class and try to just replace NSLocalizedString method with my own macro using the same.
But a serious doubt/concern that i have is, is this technique/way approved by APPLE?
i mean.. can/will this violate the apple terms of non usage of Private API or kind of overriding the same??
Coz i have tried check the same in various blogs.. but was not able to find any specific answer to the same.
Can you please confirm if this can violate the T&C of APPLE or can i go ahead with the custom macro approach?
If possible can u also provide the link/blog/tutorial from which i can understand it better?
Thanks a lot in advance.
I don't see how this is using any kind of private APIs. -[NSBundle localizedStringForKey:] is a public API. You can write whatever macros or functions you want that call it. You can even #undef NSLocalizedString and replace it with your own definition if you want, it's just a C macro.
This won't violate Apple's terms. In fact, they recommend you do this to test your app and make sure you translated all the strings. They demonstrated how to do this in the 2012 WWDC video, session 244 Internationalization Tips and Tricks at the 23:50 mark.
i was wondering about where Zends functionality comes from when inside of a controller i call
$this->getRequest()->isPost()
It works, but i do not find where this "isPost()" function comes from.
I just noticed it because i don't have intellisense for that.
Question is:
Is this merely some fallback function that "newbie users" use apart from a better alternative?
Or is it perfectly valid using it?
Thanks :)
It is the official way to go, you can use it. Check the source code of Zend_Controller_Request_Http::isPost() to see what it really is doing, if you'd like :)
I read some info regarding getting .h files for undocumented API. Most of sources recommend class-dump (or class-dump-x and class-dump-z).
However it doesn't work with iPhone Security.framework. It doesn't contain Objective-C runtime information.
The only other way which I found is to use nm or otool. This will give the names of functions and disassembly for them.
Does anybody know some faster way to get undocumented functions signature than reading disassembly and trying to figure out what parameters go where and what could it be?
You mean this undocumented api, documented here..
Security.framework is not private or undocumented.
As far as headers go, installed on my harddrive in the 3.2 sdk i find:
/Security.framework/Headers/Security.h
/Security.framework/Headers/Secbase.h
/Security.framework/Headers/SecCertificate.h
/Security.framework/Headers/SecIdentitiy.h
/Security.framework/Headers/SecImportExport.h
/Security.framework/Headers/SecItem.h
/Security.framework/Headers/SecKey.h
/Security.framework/Headers/SecPolicy.h
/Security.framework/Headers/SecRandom.h
/Security.framework/Headers/SecTrust.h
As for a little reverse engineering 101, you should realise that a framework doesn't contain or in anyway have a use for header files, or function signatures. When provided they are solely for the benefit of the developer. There is no C or C++ or objective-c code in the compiled framework, only the raw machine code.
As you have seen, if objective-c was used Class-Dump can do a pretty good job of arranging objective-c symbols into something that looks like a header file, only missing type information that isn't used at runtime, so still not that useful.
If the source language was C then you are screwed. There may be a function name symbol but there is no info about arguments or return type.
There are bunch of additional undocumented API's which are not mentioned in official documentation. As example, part of them could be seen here:
http://www.opensource.apple.com/source/Security/Security-55163.44/sec/Security/