Attribute weak extern in Swift - swift

I'm converting the obj-c framework to the Swift one.
I need to convert this line:
__attribute__((weak)) extern NSString *sdkVersion = 0;
to Swift similar one. Spend a lot of time on google, but didn't find the answer.
Predicting your questions, what I'm trying to achieve... in short words, this global variable is defined in an optional framework. My Swift function should print this version in case if our SDK is linked with that framework.
I know, I can create a wrapper (another objc framework), add necessary getters there, and then link it with the main framework. But may be there is a more simple solution?
Thanks in advance.

Related

How to use RxSwift in project with Objective-C code?

I am working in a old project that mixes Objective-C and Swift, there is a lot of legacy code in Objective-C, so migrating everything to Swift is not realistic. New code is written in Swift but Objective-C needs to be mantained with small updates.
And I have been working with RxSwift recently and I want to start using in this old project too.
The problem is the Objective-C <-> Swift interoperability.
e.g. I can't write this:
#objc let int = BehaviorSubject<Int>(value: 42)
Because I get Property cannot be marked #objc because its type cannot be represented in Objective-C
How can I deal with this situation? Is anyone using RxSwift in a mixed objc/swift project?
The core of RxSwift is the Event enum with associated values. This enum cannot be ported into Objective-C.
The answer to your question is... You can't use RxSwift in Objective-C code.
An alternative would be use ReactiveObjC in your Objective-C code and map from RxSwift Observables to ReactiveObjC Signals.

Where can I find the implementation of "class DispatchQueue : DispatchObject"?

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.

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.

Is there a native YAML library for iPhone?

I'm considering using YAML as part of my next iPhone application, but I haven't been able to find an Objective-C library to use.
The Wikipedia page for YAML mentions one, but the link is dead.
Is there an Objective-C library that can parse YAML into native collection objects (NSArray, NSDictionary, etc...)?
The Cocoa extensions for Syck are probably what you're looking for -- it's where the library that Shaggy Frog mentioned seems to be living these days.
You can try YAML.framework it's LibYAML based, it's fast and easy to use. Follows the same pattern as standard NSPropertyListSerialization.
You can use it for iOS (iPhone/iPad) development.
The YAMLKit framework is a thin wrapper around LibYAML. It does exactly what you want. For example:
[[YKParser alloc] init];
[p readString:#"- foo\n- bar\n- baz"];
id result = [p parse];
/* result is now an NSArray containing an NSArray with elements:
#"foo", #"bar", #"baz" */
[p release];
I recently wrote modern ObjC-YAML bindings, based on the standard NSCoder/NSKeyedArchiver interface: http://github.com/th-in-gs/YACYAML. I'm using them in my own projects, and intend to maintain them for at least as long as I continue to do so.
More here: http://www.blog.montgomerie.net/yacyaml
IF you are doing alot of c++ in your iPhone projects, then please have a look at yaml-cpp:
http://code.google.com/p/yaml-cpp/
has native iPhone support (via it's cmake build system)
has no dependencies beyond a good compiler and cmake
is very c++ friendly (thus, the name) with solid documentation (see the wiki/HowToParseADocument page)
I found this right from YAML's front page. But it looks like it might be out of date (c. 2004?), and the CVS link doesn't work for me.
I would bet that it's just a thin wrapper around an underlying C library like this or this... C code being "native" code that the Objective-C compiler will grok.
I found this question looking for YAML + objective C options. I ended up using this solution: https://github.com/icanzilb/JSONModel. Very cool, up to date and easy to use. Parses yaml directly into objective C models that you create inheriting the JSONModel class.