I am beginning to work my way through Neuburg's iOS Programming with Swift book, and have a real newbie question: Newburg says:
"your code always implicitly imports Swift itself." (p. 14)
But where does it import it from? Do I need to purchase this "Swift" thing in order to use the Swift language?
Is means that it imports the Swift module/framework by default.
Related
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.
I'm trying to use NSLinguisticTagger in a Swift 3.2 project for macOS.
This code works fine in Swift 4
let tagger = NSLinguisticTagger(tagSchemes: [.nameType], options: 0) // edited
But, gives the error:
Type 'String' has no member 'nameType' // edited
in the Swift 3.2 project. I tried to follow old NSLinguisticTagger tutorials but I can't find a replacement for the '.name' part. Is possible to fix this or I have to update the project to Swift 4?
NSLinguisticTagger Docs
NSHipster NSLinguisticTagger 2012 Tutorial
First of all, I need to apologize that I first wrote an answer without confirming my settings are really right. The following descriptions updated based on the settings which I believe correct.
(Xcode 9.2, target Swift Version set to 3.2. Changing the project Swift Version does not affect the target Swift Version, oh, my shame...)
When you want to work with old Swift versions, some Swift-friendly wrapper types are not available and APIs and constants are imported from Objective-C world with simple rules. In such cases, you need to re-interpret Objective-C versions of references with such rules in mind.
NSLinguisticTagScheme
As you see in the linked article above, NSLinguisticTagScheme as just a typealias of String and the constants are named as NSLinguisticTagSchemeNameType as in the article in your question's link. They are imported as-is in old Swift versions.
So, this compiles in Swift 3.2:
let tagger = NSLinguisticTagger(tagSchemes: [NSLinguisticTagSchemeNameType], options: 0)
(Still, I strongly recommend you to move to Swift 4. As Apple's official references are based on the latest version of Swift, it's Swift 4.)
I've been trying to find Swift examples for FMDatabaseQueue.
All I have been able to find is Objective-C here: https://ccgus.github.io/fmdb/html/Classes/FMDatabaseQueue.html
Im not familiar with Objective-C and I'm new to Swift so I'm not sure how to port the code.
I've found what I was looking for here https://github.com/ccgus/fmdb/issues/291
There exists Swift wrappers for SQLite that may be a better fit that fmdb which can run in Swift but does not use Swift features such as type safety or error handling. See for example my GRDB.swift https://github.com/groue/GRDB.swift which was heavily influenced by ccgus/fmdb.
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.
I am totally new to swift and developing my first application for iOS. I need to use DDMathParser with it. I followed guide at their site but i am getting errors at import statement
Expected identifier in import declaration
Expected expression
Import statement syntax:
#import "DDMathParser.h"
I followed This guide.
Bridging header files solved my problem. Thanks