How can I check the embedded functions definitions in swift? - swift

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.

Related

Simple API call within the context of DocFx preprocessor

I would like to know if it is possible to make a simple API call (e.g. GitHub API v3) within the context of a DocFx custom template preprocessor. I have been trying all sorts of different approaches, but nothing has fully worked so far.
My goal is to make a call to an API to retrieve some data, and then update the model accordingly to be used in the *.liquid or *.tmpl renderers.
I have tried using the http/https node modules. I have also tried using node-fetch. It results in a docfx build error something like:
Error:Error transforming model ".../index.raw.json" generated from
".../index.md" using "conceptual.html.primary.js". Error running
Transform function inside template preprocessor
According to DocFx documentation, preprocessors follow the ES 5.1 standard. My code conforms to this.
Does anyone know if this is possible?
By the way, I am able to do simple model manipulation just fine, so I understand the basic concepts here with the DocFx preprocessors.
Thanks!
For the benefit of others, I discovered DocFX uses jint which cannot require a Node library directly. Therefore, it appears the plugin route is a better way to go for this use case.

Only factor methods can have swift_name attribute Mapbox

I'm using cocoa pods and map box was working fine but I installed an update and this message appeared:
Now I can't run my project. I'm using map box iOS sdk 3.3.4. What should I do to fix this issue?
According to apple documentation:
The Swift compiler automatically imports Objective-C code as conventional Swift code. There may be edge cases in your code that are not automatically handled. If you need to change the name imported by Swift of an Objective-C method, enumeration case, or option set value, you can use the NS_SWIFT_NAME macro to customize how a declaration is imported. See more.
So all what I did was delete the implementation of the NS_SWIFT_NAME and with that I was able to build the project. I don't know what made this error appear but this was the best solution I found.
Example:
From this:
- (instancetype)recordWithRPM:(NSUInteger)RPM NS_SWIFT_NAME(init(RPM:));
To this:
- (instancetype)recordWithRPM:(NSUInteger)RPM;

how to find pow() methods using Swift Standard Library Reference

I'm new to Swift and is trying to understand how to use Swift Standard Library Reference. I have past experience in Java and if I want to find a class or a class's method, I simply type e.g. String.charAt() Java SE8 in Google and the first result shown is the latest offical Oracle documentation on String class. However, if I want to find a class or method in Swift, when I type in e.g. pow() Swift Standard Library Reference, google only shows the main page to Swift Standard Library Reference, not the page of the class that actually contain the method. Could someone please tell me how to actually search the Swift Library? It would help me a great deal! Thanks in advance for any help!
if you are using Xcode just go to Help > Documentation and API Reference

Realm Swift iOS7 documentation

I was just wondering if there is any written documentation on realm swift for iOS 7, since it is combination of objective c and swift.
Just to be clear, I'm not looking for official documentation, just some guidelines so I have a clearer view of what to use.
Thank you for any help.
You should refer to Realm Objective-C's documentation guide (https://realm.io/docs/objc/latest) and API documentation (https://realm.io/docs/objc/latest/api), which is applicable even when used from Swift.
As our installation instructions recommend (https://realm.io/docs/objc/latest/#installation), you should also be using RLMSupport.swift which adds some useful helpers to use Realm Objective-C from Swift. That file's source is its best documentation, it's pretty small and should be fairly readable.
Finally, to determine the exact Swift syntax when calling Objective-C methods, I recommend you either use autocomplete, or command-click a Realm.framework token from Swift, which should display Xcode's auto-generated Swift interface for the Realm module.

iPhone Undocumented API of Security.framework

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/