FMDatabaseAdditions methods not accessible in swift? - objective-c

I am porting some existing code over to swift. I am using FMDB in swift and everything has been good so far, but I do not have access to FMDatabaseAdditions methods in my project in spite of having access to everything else (FMResultSet, FMDatabasePool and so on).
I have the bridging-header file with the #import "FMDB" statement and it has the includes for all the other FMDB files.
I have looked in my build phases and I can see FMDatabaseAdditions.m in the "Compile Sources" and I have moved it to the top of the list.
Still xCode doesn't recognise it or its methods.
Any ideas?

UPDATE: Head over to the link below (in bold) for an unofficial FMDatabaseAdditionsVariadic.swift file as provided by Robert. Also keep an eye out on the repo for when the fix is officially added in.
Thanks again Rob!
-- ORIGINAL MESSAGE --
I found out what is going on from the guys on github over at FMDB repo.. (see original post here):
I notice that some of the FMDatabaseAdditions methods work fine. For example:
if db.tableExists("test") {
println("test table exists")
} else {
println("test table doesn't exist")
}
It looks like Swift is having issues with the variadic methods within the category. This is a known problem with Swift, but while I created the variadic rendition of executeQuery and executeUpdate, I didn't do so for the FMDatabaseAdditions methods. I will take care of this.
Thanks for bringing it to our attention.
Thanks robertmryan for your help.

Related

adding imports to objc bridging headers

I have been having an issue with using objective-c files in my swift project. I have come to the realization that I had already imported an objective-c file. So instead of importing another file, I decided to update the previous imported obj-c file with one more #import "STPAUBECSDebitFormView.h". this is for using stripes services.
photo below,
sorry for the false highlight, its STPAUBECS that I am having with.
with importing this file, I am getting hit with the 'STPMultiFormTextField.h' file not found and failed to emit precompiled header. However, if I were to remove that
import "STPAUBECSDebitFormView.h" I am hit with the image below,
I am trying to understand how to use multiple languages inside of swift. would really appreciate it if someone could help me understand how to use stripes obj-c language inside of swift.

How do I use Objective-C code from Github in my Swift program?

Summary of problem
I'm building a calendar app in Swift, and I'd like to start with the UI in this repo: https://github.com/erichoracek/MSCollectionViewCalendarLayout
This repo is written in Objective-C.
However, I'm not sure how to build on top of this Github repo using Swift.
Example of the UI I'd like to use in my calendar:
What I've tried
I successfully installed this library with CocoaPods.
I ran $pod install.
I successfully ran import MSCollectionViewCalendarLayout.
I added a new CollectionViewController on my Storyboard, and assigned it to my custom CalendarViewController class
I tried (dumbly) with the code below in class CalendarViewController,but I get this error message:
"Cannot assign value of type 'MSCollectionViewCalendarLayout.Type' to type 'UICollectionViewLayout'"
override func viewDidLoad() {
super.viewDidLoad()
self.collectionView.collectionViewLayout = MSCollectionViewCalendarLayout
}
I understand I probably have to use self.collectionView.register(cellClass:forCellWithReuseIdentifier:)...but how?
There's some documentation titled "Usage" in the Github, but unfortunately I'm still lost as to how to use it:
There's also an Example.xcworkspace included, written in Objective-C. I've gone through most of it. They include header (.h) and implementation (.m) files for each of the elements that they use.
There's a good answer to a tangential problem here: https://stackoverflow.com/a/45540130/3979651, but this doesn't directly solve my problem. I'd like to import this Cocoapods library, instead of writing on top of Objective-C files. But I'm also not entirely sure if this is the right / best way to do it.
Summary of questions
How do I link my CollectionViewController to MSCollectionViewCalendarLayout so that it has the same UI?
How do I use self.collectionView.register(cellClass:forCellWithReuseIdentifier:) in this case?
Do I have to write a new file for each element, like in the Example? (Event cell, Day Column Header, etc.)
Or, would it be easier to just copy and paste the Example element files (.h and .m) into my app? If so, how do I build on top of those files?
What I'd like to accomplish
I would like to import MSCollectionViewLayout like a library, attach it to my own CollectionViewControllers, and build my own functionality on top of this, all using Swift.
Thank you all in advance! Hopefully I can commit the correct answers here to the repo's README.md file.
You can better use one of the below repos which are purely written in Swift and has the same UI as of MSCollectionViewLayout
1) CalendarKit
2) Calendar
Note: I personally used these libraries and these are easy to
integrate with your existing application.

Why the Xcode objective c interface header name isn't found for Swift 4 language

I am currently working on an Objective C project and need few swift files support in it. According to Apple official guidelines, after I create a bridging header, I did this
#import "ProjectName-Swift.h"
to access the swift classes. It didn't work. So, I changed the "Defines Module" to "YES", rewrote the header prefixing with the module name, all to vain. Then I thought of switching the compiling language to "Swift 3" and voila, it works! App runs on the phone.
However, there are few plugins and frameworks that I am also using which don't work with Swift 3. So, no peace here. I need a solution. Help!
So finally after searching the web an another SO post (answer) helped me out. It could be because of bridging issues or compiling thing, I have to "BUILD" the project to get the header generated or something. The solution was from this post https://stackoverflow.com/a/45338549/8102549 or here
Check out your Build settings for Objective-C generated Interface Header Name make sure that the Install Objective-C Compatibility Header is set to Yes. Also, ensure the file name there is as you expect.

Can Swift code embed in existing Objective-C file - or must one add that code to a discrete Swift file?

I have an Objective-c file which used to work with the older XCode's
with the emergence of XCode 6.x - code no longer performs
I found the same functionality in code written in Swift online
I read Apple's documentation about using bridging header's to allow the use of Swift with Objective-C. I was able to get that setup ok, I do believe.
What is not clear is - can I simply cut and paste the Swift code into my Objective-C file (a viewcontroller.me file actually), or am I limited to having to use a Swift file from the start ?
If I have to use a new file in my (very simple) app, Im not quite sure how to pull off having two viewcontroller.m files do the work where one used to work fine, so this method obviously creates a new problem for me.
Thanks for your assistance in advance !
I would recommend just creating a class or struct for your swift code, and access that class or struct in your Objective-C ViewController.

Why doesn't Xcode suggest #synchronized?

I only rarely use #synchronized, but as far as I can remember (meaning around Xcode 3.2 or something), it never suggested #synchronized when using the auto-completion, and still never does.
I do get suggestions when typing '#', like #autorelease, #encode, #selector and so forth.
Is there any known reason for this ? I wasn't able to find any related topic. It's been bugging me, because it gives me the feeling that this is not a valid method to handle concurrency in iOS.
#synchronized does not appear when using auto-completion because Apple has not mapped that keyword to any code sense implementation.
Per Apple's suggestion, I have filed a bug report.
However, I can offer an auto-complete solution.
You may create an #synchronized snippet that can be auto-completed or drag and dropped into your code.
Copy/paste the code below into one of your Xcode documents.
Select the new code and drag it to your snippets library.
Double-click the new snippet and click edit.
Enter #synchronized for the completion shortcut.
For more info: http://nshipster.com/xcode-snippets/
#synchronized(anObj) {
// Everything between the braces is protected by the #synchronized directive.
}