SQLite.swift: Can't retrieve table count due unrecognized token: ":" (code: 1) - sqlite.swift

My current code is written with Swift 3 ,I tried to change Swift 4.2 via Xcode10.1.
SQLite is crashing on changes version and working correct on old code.
I'm trying to retrieve a count of records in a table using SQLite.swift and Swift in a Cocoa macOS application.
let db = try Connection("\(pathh)/db.sqlite3")
let users = Table("users")
var count = try db.scalar(users.filter(userid == userid).count)
However, when this code is executed (from a button click event handler), the following exception is thrown:
unrecognized token: ":" (code: 1)
When I tried to use var count = try db.scalar("SELECT COUNT(*) FROM users WHERE userid=?",userid) as! Int64
, the correct result is returned.
Any and all help would be appreciated. Thanks in advance!

In my project,I required updating was the following in my Podfile:
pod 'SQLCipher', '~>4.2.0'
pod 'SQLite.swift/SQLChiper', '~>0.12.0'
After pod update unrecognized token: ":" (code: 1) is solved.

Related

requery android - ambiguous method call for select

Using requery version 1.5.0 ReactiveEntityStore for select calls.
But the compiler giving error for below call -
Observable<Result<Person>> result = mDataStore
.select(Person.class)
.where(Person.CATEGORY.eq(category))
.orderBy(Person.SEQUENCE.asc())
.get()
.observableResult();
Error details:
https://i.stack.imgur.com/bdPlY.png
I'm not sure about how you got that particular error message (maybe I can edit if you add more information about the actual classes involved).
However, it seems like you are mixing Result with ReactiveResult, what you want is probably:
// Supposing this is your definition of the data store:
ReactiveEntityStore<Person> mDataStore;
// Your result is going to be Reactive, next line is the one changed!
Observable<ReactiveResult<Person>> result = mDataStore
.select(Person.class)
.where(Person.CATEGORY.eq(category))
.orderBy(Person.SEQUENCE.asc())
.get()
.observableResult();

UI Testing Failure

Here is auto generated code. I didn't modified it.
func testExample() {
let app = XCUIApplication()
let defaultStaticText = app.tables.staticTexts["Default"]
defaultStaticText.tap()
}
Error I got is:
UI Test Activity:
Assertion Failure: UI Testing Failure - Failure getting list of active applications: AX error -25205
Screenshot of the app:
All I did during the test is tapping on the Default row on top. I did this in Simulator. The error appears on the last line: defaultStaticText.tap().
Have you tried to use completely different names for “Default” and “Default configured”?
I think you get multiple cells for
let defaultStaticText = app.tables.staticTexts["Default"]
You can learn more from here.

Error: "include is invalid for non-ParseObjects" (using parse-osx-library-1.7.5)

I have a Meal object that stores pointers to n created objects "FoodInfo" using the key "MealItems".
When I query for the meal I take advantage of the [query includeKey:#"MealItems"] to fetch the items pointed to while fetching the "Meal".
This works swimmingly if the objects are created while online (ie. all are stored in the cloud db).
However, since I cannot assume access to the cloud at all time for this app I am now trying to enable the local datastore so I've changed my queries to use:
[query fromLocalDatastore];
and I've changed all of my objects' save methods to pinInBackgroundWithBlock followed by (assuming success of local save) saveInBackgroundWithBlock followed by (assuming failure) saveEventually.
To test this, I:
turned off wifi
ran the code to create a meal and then add newly created foods to it. This works with no error codes.
ran a report that then queries for the meal just created. This fails with the following:
Error: Error Domain=Parse Code=121
"include is invalid for non-ParseObjects" UserInfo=0x60800007f400 {
error=include is invalid for non-ParseObjects,
NSLocalizedDescription=include is invalid for non-ParseObjects,
code=121
} {
NSLocalizedDescription = "include is invalid for non-ParseObjects";
code = 121;
error = "include is invalid for non-ParseObjects";
}
Is this scenario not supported?
When I re-enable wifi, the meal is successfully added to the online db, but the query failure still happens when I run the query with the includeKey locally.
Am I missing something here? I'm quite surprised to see this failing. It seems like a really basic feature that should work whether local or cloud based.
Parse objects are not created until you save them. Try using saveEventually first before using pinInBackgroundWithBlock.

Swift 2, warning: could not load any Objective-C class information from the dyld shared cache

I have found a few questions regarding this issue, yet none of them were helping with my problem. I am trying to save an object to core data using this code (which worked perfectly fine in Xcode 6 and Simulator...):
let fetchRequest = NSFetchRequest(entityName: "Patient")
let fetchedResults : [NSManagedObject]!
do {
fetchedResults = try managedContext.executeFetchRequest(fetchRequest) as! [NSManagedObject]
patienten = fetchedResults
} catch {
print("error")
}
I added the do-try-catch once I started working on this project in the Xcode 7 beta and a physical device.
Now, when I hit the Save button, this piece of code is called, the app freezes and I get the following:
warning: could not load any Objective-C class information from the dyld shared cache. This will significantly reduce the quality of type information available.
Does anybody know where I went wrong?
For anyone coming across this in the future, I just ran into this problem myself and it turned out that I was actually getting a stack overflow from a recursive function.
Apparently calling setValue:forKey: on an NSObject calls the respective set[Key] function, where [Key] is the (capitalized) name you gave to the forKey section.
So, if like me, you have code that looks like the following, it will cause an infinite loop and crash.
func setName(name: String) {
self.setValue(name, forKey: "name")
}
Choose Product > Clean
I had similar issue. I deleted the app from the device. Then "Product->Clean" in the XCode menu. When I ran the app again, the issue got resolved.
Swift 3:
Actually this problem happened often when you have any property in input declared as type NSError and the compiler expect an Error output, so change the input type to Error usually solve this issue.
What helped me in similar problem (xCode 7, Swift 2):
reading this question
Or more quickly without explaining the reason of solution: just comment #objc(className) in your NSManagedObjectSubclass , that was generated from your CoreData Entity (#objc(Patient) - in your case ).
This solution (if issue still appears) does not applicable to xCode 7.1/Swift 2.1, as the way of generating NSManagedObjectSubclasses was changed.
Don't forget about cleaning your project (Product > Clean) and deleting the app from your device/simulator to replace CoreData storage on it.
let fetchRequest = NSFetchRequest(entityName: "Patient")
do {
let fetchedResults = try managedObjectContext!.executeFetchRequest(fetchRequest)
print("\(fetchedResults)")
} catch {
print("error")
}
The above code worked for me.
Maybe the issue maybe with how your core data is managed.
Check if your managedObjectContext is actually getting created.
Check the modelling of your core data

How to create a VPN connection in Swift on OS X?

I followed the steps described in this tutorial.
I tried to translate the code from Objective-C to Swift. This is the code I have:
var l2tpInterface = SCNetworkInterfaceCreateWithInterface(
kSCNetworkInterfaceIPv4,
kSCNetworkInterfaceTypeL2TP
).takeUnretainedValue();
var pppInterface = SCNetworkInterfaceCreateWithInterface(
l2tpInterface,
kSCNetworkInterfaceTypePPP
).takeUnretainedValue();
var prefs = SCPreferencesCreate(nil,"SoybeanVPN",nil).takeUnretainedValue();
var service = SCNetworkServiceCreate(prefs, pppInterface).takeUnretainedValue();
var success = SCNetworkServiceEstablishDefaultConfiguration(service);
This code returns a runtime error EXEC_BAD_ACCESS(code=1) at the first line.
I googled this error and someone said the problem is caused by using released object in Objective-C? Is that the same in Swift? Does anyone have any experience with VPN creation in Swift?
UPDATE:
I tried to debug and find the const value of kSCNetworkInterfaceIPv4 is invalid, see the attached image:
Is that a bug of Swift?
I believe kSCNetworkInterfaceIPv4 is not the problem, because I can use it just fine to create L2TP/IPSec and Cisco VPNs using Swift.
It's rather tricky to handle C pointers in Swift, but this is how I do it, using Swift 2.3. Notice the wrapping/unwrapping with ! of C-Reference objects.
let initialTopInterface: SCNetworkInterfaceRef!
let initialBottomInterface: SCNetworkInterfaceRef!
// L2TP on top of IPv4
initialBottomInterface = SCNetworkInterfaceCreateWithInterface(kSCNetworkInterfaceIPv4, kSCNetworkInterfaceTypeL2TP)
// PPP on top of L2TP
initialTopInterface = SCNetworkInterfaceCreateWithInterface(initialBottomInterface!, kSCNetworkInterfaceTypePPP)
let service = SCNetworkServiceCreate(usingPreferencesRef, initialTopInterface!)
// Now you assign the attributes
SCNetworkServiceSetName(service, ("Some Name" as CFString))
// myConfiguration is a Hash with your relevant Key/Value pairs
SCNetworkInterfaceSetConfiguration(topInterface!, myConfiguration)
// Here is a good example for why Swift may just crash if you're not careful
let temporaryString:CFString = "IPSec"
SCNetworkInterfaceSetExtendedConfiguration(topInterface!, temporaryString, myL2tpConfiguration)
SCNetworkServiceEstablishDefaultConfiguration(service)
You can find a working implementation (for macOS Sierra) on Github
Just need copy all SCNetworkInterface's
SCNetworkInterfaceCopyAll()
Insert it at the beginning, before creating interfaces

Resources