I've never messed with iOS so this is all new to me. I'm trying to import SQLClient into an an existing Xcode project. (I need to fire off an INSERT from the iOS app.)
https://github.com/martinrybak/SQLClient
I've tried both installation methods listed by Martin via cocoapods and manual but I can't get either to work.
For option #1) everything worked fine until I tried pod install and was met with
Analyzing dependencies
[!] The dependency SQLClient (~> 0.1.3) is not used in any concrete target.
I was expecting the command to produce a file named SQLClient.xcworkspace. I wasn't sure if this new xcworkspace file was meant to replace my main project xcode file. But since it didn't work, I moved onto option #2.
For option #2 I wasn't sure where to put the contents. (Does Martin mean /SQLClient/SQLClient/SQLClient/SQLClient or /SQLClient/SQLClient/SQLClient?)
Was I supposed to copy just the files or the whole folder?
Do the contents go into my project at the same level as my original xcode project file or in a subfolder?
I've tried a couple variations but I admittedly don't know where the SQLClient files/folders should be placed in relation to my other project files.
I've tried messing with my bridge file as well but I've been unable to properly load it.
I have some time (2 days) to figure this out so I'm willing to learn but I need some guidance.
Here's a pic of my existing Xcode project and latest attempt to import SQLClient.
It looks like you have all the files in your project correctly.
Things to check.
If you said yes to create the bridge file when you dragged the object-c file into the project then you just need to add #import "SQLClient.h" to the bridge file. If you created the bridge file manually make sure it is added to Build Settings - Objective-C Bridging Header.
Make sure in your target - general - linked framework and libraries you have libiconv.tb and libfreetds.a
Swift 3
class testViewController: UIViewController, SQLClientDelegate {
// Handles errors from the SQLClient
func error(_ error: String!, code: Int32, severity: Int32) {
print("\(error!) \(code) \(severity)")
}
//MARK: Lifecyle
override func viewDidLoad() {
super.viewDidLoad()
let client = SQLClient.sharedInstance()!
client.delegate = self
client.connect("ServerNameOrIP", username: "cool", password: "cool", database: "database") { success in
client.execute("SELECT * FROM table", completion: { (_ results: ([Any]?)) in
for table in results as! [[[String:AnyObject]]] {
for row in table {
for (columnName, value) in row {
print("\(columnName) = \(value)")
}
}
}
client.disconnect()
})
}
}
}
Created a sample project here
I was able to get installation option #1 working after changing the pod file to include a target.
target "TargetName" do
pod 'SQLClient', '~> 0.1.3'
end
I downloaded SQLClient manually and it worked for me.You will get the steps to connect from swift project from here - https://github.com/salmasumona/Call-SP-from-iOS-project-using-SQLClient
SWIFT 5
enter image description hereThe best way to use Obj-C in a Swift project is to use a bridging header file, what I did with SQLCLient was to drag and drop the files from SQL client and then Xcode will ask if you want to create a bridging header file, select yes.
Inside the bridging header file, import "SQLClient.h", from here you can build the project and everything should compile. You can then create a SQLClient object like you did above and inside the .connect you make the sure the completion handler checks if it was successful then inside the closure you can call client.execute and from here if you put a SQL command as a string and use data as a variable inside the .execute completion block, if you print this data variable you will return all of the data from the SQL Server. It returns in JSON, so from here you can convert using JSON Serialization.
If you have any questions, please feel free to message me and I will return a screenshot of what my code looked like so that it may help you!
Related
There was a version of Leaf that I was using to load .html files instead of .leaf ones from my Vapor project, which would make syntax coloring for those same files done automatically.
The version of Leaf was 4.0.0-tau.1 and the one for LeafKit was 1.0.0-tau.1.1
When using this particular version, I could setup leaf in the configure.swift file this way:
/// Change the classic .leaf extension to .html for the syntax
/// coloring option of Xcode to work each time the app is being load up.
fileprivate func leaf(_ app: Application) {
if !app.environment.isRelease {
LeafRenderer.Option.caching = .bypass // Another issue from the update
}
let detected = LeafEngine.rootDirectory ?? app.directory.viewsDirectory
LeafEngine.rootDirectory = detected
LeafEngine.sources = .singleSource(
NIOLeafFiles(fileio: app.fileio,
limits: .default,
sandboxDirectory: detected,
viewDirectory: detected,
defaultExtension: "html"))
app.views.use(.leaf)
}
In this code, the LeafRenderer.Option.caching = .bypass and the code used with LeafEngine do not work anymore since having updated Leaf to 4.1.3 and LeafKit to 1.3.1.
How can I successfully make this code work as before with the updated Leaf and LeafKit frameworks?
You can use this Xcode plugin:
https://github.com/OmranK/VaporLeafPlugIn
It adds Vapor Leaf language support to Xcode IDE. Provides syntax highlighting for Leaf tags as well as HTML tags with auto-indentation all together.
At the moment the plugin supports Xcode up to 13.2 beta. Future Xcode versions will require small update (add new DVTPlugInCompatibilityUUID) but it can be easily handled even on already installed plugin.
I am trying to add a Skeleton-templated view to a recent Vapor 2 app that, so far, only produces JSON output with a MySQL database. If I use the following minimal code:
get("viewTest")
{ req in
let params = try Node(node: [ "name": "nick"])
return try self.view.make("index",Node(node:params))
}
The file index.leaf exists in the Resources/Views folder and the documentation suggests that omitting the .leaf suffix is fine, but doing so gets:
[Data File Error: unable to load file at path /Users/test/Library/Mobile Documents/com~apple~CloudDocs/Apps/Vapor/testServer/Resources/Views/index]
However, if I put the suffix in explicitly, self.view.make("index.leaf",Node(node:params)), the contents of the file are output without being rendered:
#extend("base") #export("body") {#(name)}
I have tried putting the code directly into Main.swift and that makes no difference and putting it into a handler. I've also tried creating a new Vapor 2 project from scratch (using a fresh install of vapor) and it behaves the same. It seems odd that something so fundamental doesn't work out of the box.
It turns out that although the default renderer for Droplet is 'leaf', the default setting in Config is 'static'. Putting:
"view": "leaf"
into Config/drop.json fixed the problem.
I am currently trying to import a CSV file using CSVImporter. The github repo says that it is up to date with the current Swift version 3.0. However I am getting an error which I couldn't find a solution to on the internet.
This is the error: http://imgur.com/imhSoQi
This is the github repo: https://github.com/Flinesoft/CSVImporter
I would gladly provide anymore information if needed.
These errors are unrelated to the CSVImporter library.
The first error happens because you are referring one ivar from another. Essentially this is not valid in Swift:
class ABC {
let hello = "Hello"
let hello_world = hello + " World" // references 'hello'
}
The second error happens because you directly put code into your class. Code in Swift lives in methods or in initialisers, but not directly in a class.
I think this may be what you want:
class ViewController {
let path = "/tmp/blub.csv"
func load() {
let importer = CSVImporter<[String]>(path: path)
importer.startImportingRecords ... {
...
}
}
}
And if this is part of a VC (e.g. you might want to display the CSV in a tableview), you probably want to load the data off the main queue, not in init().
P.S.: Do not only send image links to source code. Copy/paste the relevant source code into the question.
I'm trying to create a mixed ObjC-Swift framework. But I'm losing a lot of hairs trying to make a private module for my Swift files.
I followed some steps in iOS mixed dynamic framework - bridge objc headers with private module combined with some steps in https://stackoverflow.com/a/36878037/749438
Basically I have a module.modulemap now which has the following content:
module MyCore { //Adding 'framework' before module is giving me an "Umbrella not found"-error :/
umbrella header "MyCore.h"
export *
module * { export * }
explicit module MyCorePrivate {
header "MyCore_PrivateUmbrella.h"
export *
}
}
The MyCore_PrivateUmbrella.h imports all headers I want to privately expose to my Swift code. The reason behind it is just that it's easier to include 1 header in the module then all the to-be-exposed headers (since you need to include the specific paths to the headers...).
My build settings look like:
DEFINES_MODULE: YES
PRODUCT_MODULE_NAME: MyCore
CLANG_ENABLE_MODULES: YES
SWIFT_OBJC_INTERFACE_HEADER_NAME: MyCore-Swift.h
SWIFT_INCLUDE_PATHS: path to the directory of the module.modulemap
and last but not least; ALWAYS_SEARCH_USER_PATHS is set to NO
In my Swift files I import the module using import MyCore.MyCorePrivate. This works as expected and I can use my code from Objective-C.
Building the project gives me an error like this (the black bars only hide the project name and path to the file):
Now clicking the error brings me to the generated MyCore-Swift.h where the #import MyCore.MyCorePrivate is seemingly wrong.
I've got no idea as of why it's wrong, neither do I know how to fix this. Especially since it's a file generated by XCode.
Does anyone knows what's going down here?
You will need to modify the resulting framework after building it:
1) Don't create any private modules. Revert back to default settings.
2) Any code you want to expose to swift add to your framework header and make sure the headers are set as public in the build section or else swift code wont have access. (Use the <> syntax)
3) Any code from swift to objc make public.
4) Compile you project
5) go to your framework build directory (i.e MyFramework.framework)
6) open the framework header file in the headers directory of the framework (Myframework.h file)
7) Delete all the import statements that should have been private from the framework header
8) Delete all the .h files for the headers that should have been private from the headers directory ( you removed the import statements from the main framework header)
9) go to the .module file and remove the swift modules section
The module file should be very bare bones:
framework module MyFramework {
umbrella header "MyFramework.h" export * module * {export *}}
I am getting this error after adding to an extension a class from another extension:
Uncaught TYPO3 Exception
#1247602160: Table 'deva.tx_bingoprizes_domain_model_hall' doesn't exist: SELECT tx_bingoprizes_domain_model_hall.* FROM tx_bingoprizes_domain_model_hall WHERE tx_bingoprizes_domain_model_hall.uid IN ('0') LIMIT 1
Tx_Extbase_Persistence_Storage_Exception_SqlError thrown in file
/home/typo3_src/typo3_src-4.5.32/typo3/sysext/extbase/Classes/Persistence/Storage/Typo3DbBackend.php in line 1008.
The class added is tx_bingoprizes_domain_model_hall which should be reading from the table tx_bpscore_domain_model_hall as I added to the setup file:
config.tx_extbase.persistence.classes {
Tx_Bingoprizes_Domain_Model_Hall {
mapping {
tableName = tx_bpscore_domain_model_hall
}
}
}
as I did for other extension which also reuses this class and which works properly ( I use it as my model for how to do this and as near as I can tell did everything the same way ). Why is typo3 still trying to use table tx_bingoprizes_domain_model_hall? where else do I need to specify the other table? I tried restarting the server, clearing caches, reinstalling the extension but still get the error.
I am using the latest 4.5 typo3.
Thanks
to reiterate my comment as the answer...
OK, I got it. Once again I had forgotten to INCLUDE the necessary item (in this case bingoprizes) to the page's template. So the error was not in my extension but in the typo3 config for the page. I hate that, forget it all the time, it is counter-intuitive to me as I find it natural to assume the setup.txt stuff is auto included on any page that uses my extension.