Search user engine with Firebase - swift

I want to implement a search user engine on my app. It is writen with swift and has a Firebase backend. The problem is that I don't find any help on the web.
My data is structured like this:
https://i.stack.imgur.com/N7qbT.png
I tried with this code and others, but still don't working:
Database.database().reference().queryOrdered(byChild: "fullname").queryEqual(toValue: "michel dupond").observe(.childAdded, with: { (snapshot) in
print("Snapshot:", snapshot as? [String: String])
}

Will your search always contain a full name? If you want to implement something like contains(value: String) I'd recommend using Algolia to add string searches.

Related

Get CallerId (Username) from incoming call Linphone - Swift

I've just found a simple way to get the some CallLogs (CallerID, Username, To, From, Call duration, Date, Status, ...) from the new Linphone library for swift (SDK 5.0).
I just want to share it with you
Referring to Linphone's documentation, and some testings, I found at least 2 simple ways to retrieve the CallLog and read it:
1. Using CoreDelegateStub
CoreDelegateStub( onCallStateChanged: { (core: Core, call: Call, state: Call.State, message: String) in
So, you can use the call attribute to get the CallerID(Username) for example, like that:
call.callLog?.fromAddress?.username
Remember, the callLog object contains a ton of parameters that you can find in the documentation
2. Using Core from Linphone wrapper
var mCore: Core!
self.mCore.callLogs
In that way, you can retrieve all your call logs in an array, so you will need to choose an item and get the attributes from it like I've shown above.
self.mCore.callLogs[0].fromAddress?.username

Query Parent by Child Relation ParseSwift

I am looking to query my parent ParseObject by a child relation object. I have a parent named Matches which has a field Relation(Wrestlers). I want to find all matches that a wrestler belongs to. Any assistance is greatly appreciated as I can only find documentation for outdated version of the ParseSwift library and the playground doesn't seem to help as it only uses built in relationships and not custom objects.
This query does not return any results. Wrestler is set to an instance of the ParseObject I want to filter the relation on
let query = Match.query("wrestlers" == wrestler).includeAll()
The playgrounds for Roles and Relation states:
Using this relation, you can create many-to-many relationships with other ParseObjecs, similar to users and roles.
Essentially if you follow the Roles example, you should be able to create any relation and query. Specific for your use case (at least using the small amount of code you provided in your question):
let match = Match() // Next time, please provide the code for all of your ParseObjects in question.
let matchRelation = match.relation("wrestlers", child: wrestler)
do {
let wrestlers = try await match.relation.query(wrestler).includeAll().find()
print("Found related wrestlers: \(wrestlers)")
} catch {
print(error)
}
In ParseSwift 2.4.0+ you can do the following:
let matchRelation = match.relation("wrestlers", child: wrestler)
do {
let wrestlers = try await wrestler.relation.query("wrestlers", parent: match).includeAll().find()
print("Found related wrestlers: \(wrestlers)")
} catch {
print(error)
}
You can refer to the Playgrounds in the pending PR if more clarity is needed.
I can only find documentation for outdated version of the ParseSwift library and the playground doesn't seem to help as it only uses built in relationships and not custom objects.
This can't be true as the only documentation for the ParseSwift SDK is the API documentation and the Swift Playgrounds which are both up-to-date. If you are referring to the iOS SDK's documentation that is a completely different SDK than the ParseSwift SDK. The iOS SDK is an Objective-C SDK that bridges to Swift and the SDK's are not related.

Swift - Read Google Sheets

I'm working on an app that uses Google Sheets as a database, but I can't figure out how to get Swift to read from google sheets. I've looked through the API website and a few questions on here but I need some help just getting started. So far I have;
private let scopes = [kGTLRAuthScopeSheetsSpreadsheets]
private let service = GTLRSheetsService()
var range = "Form Responses 1!A1:D3"
let spreadsheetId = "p;;;;;;p;;;;;;;;1LqXa6v75JE8RQQDOI4Z_g8mUT8x0DhsEDwRIaxDN-DU" // Portfolio
let query = GTLRSheetsQuery_SpreadsheetsValuesGet.query(withSpreadsheetId: spreadsheetId, range:range)
service.executeQuery(query, delegate: self, didFinish: #selector(displayResultWithTicket(ticket:finishedWithObject:error:)))
Which I got from another question on here...
But 'displayResultWithTicket' is an unresolved identifier. Currently it gets to the last line, and debugging I'm not even sure what to do with the 'query' value. I'm really not even sure if it's reading the correct spreadsheet. How can I tell?
Long story short, I'm lost.
I recently made an app that uses Google Sheets. But I used the CSV file for the database. This might help. If you want, I can share the details.
First you need to export the Google Sheets file in CSV format. I used Realm to read CSV. Using Realm Studio, you need to create the columns as in the CSV file. Then you can import the CSV file into Realm Studio. Your database is ready.
In didFinishLaunchingWithOptions to find the file created after installing Realm on your project
print(Realm.Configuration.defaultConfiguration.fileURL!.path)
Now we will use the database with Swift.
For this, we must first add the Realm file that we prepared to the XCode project directory. Then we use it in ViewController this way to get data.
var realm : Realm!
For get the data in default.realm file
let realmPath = Bundle.main.url(forResource: "default", withExtension: "realm")!
let realmConfiguration = Realm.Configuration(fileURL: realmPath, readOnly: true)
do{
realm = try Realm(configuration: realmConfiguration)
}
catch {
print("error \(error.localizedDescription)")
}
You can export the result to an array. I hope it helps.

How do you retrieve data from Firebase that has been manually entered?

I'm creating a new iOS app for a lacrosse team. I've manually added a registrationCode into my Firebase database.
I've tried getting a reference to the database and then using the .observe method to get the value but it crashes.
My latest code attempt:
let rootRef = Database.database().reference().child("groove-lacrosse")
rootRef.observe(.value, with: {snapshot in
print(snapshot.value as Any)
})
What's the correct way, programmatically, to retrieve Firebase data that was manually entered?
The image is the Firebase entry
It looks like groove-lacrosse is the name of your database, in which case you don't need to specify that anywhere.
Instead you can just read the registration code directly and then print its value:
let rootRef = Database.database().reference().child("registrationCode")
rootRef.observe(.value, with: {snapshot in
print(snapshot.value as Any)
})

how to save related core data objects to parse with swift

My app is a simple word list sharing app. There are entities of Owners who own entities Wordlists with entities of related words in CoreData. In one screen I want to be able to save a wordList and its related words and owner to Parse on the push of a button. Then in another screen I want to be able to download a WordList and its related words, then save it to core data. present the name of the list in a table. The code I have is:
// To save the wordList to Parse:
#IBAction func shareWordList(sender: AnyObject) {
let parseWordList = PFObject(className: "WordList")
parseWordList.setObject("\(wordList?.listName)", forKey: "ListName")
parseWordList.setObject("\(wordList?.owner)", forKey: "Owner")
parseWordList.setObject("\(wordList?.words)", forKey: "Words")
parseWordList.setObject("\(wordList?.isSharedDate)", forKey: "IsSharedDate")
parseWordList.setObject("\(wordList?.isShared)", forKey: "IsShared")
parseWordList.setObject("\(wordList?.createdDate)", forKey: "CreatedDate")
parseWordList.setObject("\(wordList?.isAppList)", forKey: "IsAppList")
parseWordList.saveInBackgroundWithBlock { (succeeded, error) -> Void in
if succeeded {
print("object uploaded")
} else {
print("Error: \(error) \(error?.userInfo)")
}
}
This uploads ok for most items, but the words and owner related to the wordList are not saving.
Is it possible to use the relationship properties like this with Parse? How would I then get a shared wordList and all its properties back from Parse into CoreData?
Thanks in advance to anyone for some help with this....
This code "\(wordList?.words)" is getting the human readable description of the relationship contents. That is a log description of the NSSet of managed objects. That's why you get basically gibberish in the parse data store.
What you really want to do is to get the relationship and then ask for the name of each item. You can do that with KVC. When you have that it would be an NSSet of strings that you can use to store directly.
Arguably it would be better to have multiple different classes in the parse data store which match the entities in your core data model. If you do that then you can process the relationship items to create new objects in the parse data store and then add them (once saved) to parse relationships.
It's also possible to use the REST interface to parse with a library like RestKit to map from your parse data store contents directly into core data.