Firebase real time database Batch update - swift

I have a list that can be deleted by a user with a click of a button. However, I cannot find documentation for firebase batch methods. Can someone point me in the right direction?
I want something like this..
Database.startBatch
for x in y {
let ref = Network.database.child(x)
ref.updateChildValues(status: done)
}
Database.beginBatch

Related

fire base custom search is stuck

I am doing firebase programming with iOS.
I could do normal searching with code like below
ref.child("Users").queryOrderedByChild("name").queryStartingAtValue(text).observeEventType(.Value, withBlock: { snapshot in
for u in snapshot.children{
print(user.name)
}
})
but i am confused, as i want to find people near me. every record has lat long values, where in the server i would put code to evaluate distance between my current location and friends location and filter them ? I dont want to loop through all items in above for block (Client side)
Also, can i write server code to make services hosted in firebase ? what is the recommended way to get data from big server like redshift ?
Is firebase really drag-drop development ? i did not find anything of that sort in firebase documentation ! firbase-ui is open source, but it gives obj c code and no drag and drop ! request answer please

Don't want to download all objects

I'm having a hard time understanding how I should structure my iOS app with regards to how Firebase works. I've got a few thousand users with my current implementation (not using firebase currently), but using .childAdded will give me all of the items in my db (of course to start with) but I'm trying to build something with .childAdded that allows me to say download the first 20 items, then as they scroll the tableview it downloads the next 20 items. My users post a lot of photos and their feed would be blown up with the amount of posts that .childAdded returns.
Thoughts on what to do?
This may help you better understand how to convert Firebase Queries into equivalent SQL Queries.
https://firebase.googleblog.com/2013/10/queries-part-1-common-sql-queries.html#paginate
// fetch page 2 of messages
new Firebase("https://examples-sql-queries.firebaseio.com/messages")
.startAt(2) // assumes the priority is the page number
.endAt(2)
.once('value', function(snap) {
console.log('messages in range', snap.val());
});
Here you can see the documentation that Explains Queries
You can go to the part that says limitToFirst.
For Example this says to limit to last 10:
var rootRef = firebase.database.ref();
var usersRef = rootRef.child("users");
var usersQuery = usersRef.limitToLast(10);
usersQuery.isEqual(usersRef); // false
usersQuery.isEqual(usersRef.limitToLast(10)); // true
usersQuery.isEqual(rootRef.limitToLast(10)); // false
usersQuery.isEqual(usersRef.orderByKey().limitToLast(10)); // false

Pulling data from a GKLeaderboard

Okay, so I have spent a large amount of time searching the internet for help on this to no success, so I would like some help.
I am making a game with SpriteKit, and I have decided to implement my own leaderboard style, rather than the clunky Game Center default. I have managed to log the user into GC, but cannot find the correct (and working) Swift 3 code for pulling information from the leaderboard. I want to pull the top 10 score, along with the current user score (if they aren't already in the top 10). The information I would like from them is position, username and score.
I know this is a fairly simple concept, but every tutorial online either uses the default GC view, or is extremely old/outdated code which no longer works. I just need to know how to pull this information from the leaderboard, then I can process it all myself!
Thank you for any help in advance!
It seems like Apple doesn't have proper example code in Swift, but here's a Swift version loosely based on their Objective-C example:
let leaderboard = GKLeaderboard()
leaderboard.playerScope = .global
leaderboard.timeScope = .allTime
leaderboard.identifier = "YourIdentifier"
leaderboard.loadScores { scores, error in
guard let scores = scores else { return }
for score in scores {
print(score.value)
}
}
Note, this is just a translation from Apple's Objective-C code, and I haven't tested it with real data.

How would I go about limiting a users action utilizing Parse?

This is all purely for educational purposes, to help me get a better understanding of how Parse as well as Swift operates.
I would like to make it so a user is only able to like an item once (not being able to hit a button multiple times), as currently, I'm utilizing an anonymous system with Parse.
Would I essentially use an if method with PFUser.CurrentUser() in the likeButton method to halt a user from hitting like again or would I use NSUserDefaults?
I'm not able to post code currently as I'm not near my laptop, however I could later if it helps. Still curious if I could get some info before that however.
Sample code I found on here from a previous question, which essentially implements the same idea.
#IBAction func likeButton(sender: AnyObject) {
let hitPoint = sender.convertPoint(CGPointZero, toView: self.tableView)
let hitIndex = self.tableView.indexPathForRowAtPoint(hitPoint)
let object = objectAtIndexPath(hitIndex)
object.incrementKey("count")
object.saveInBackground()
self.tableView.reloadData()
}
Would I call NSUsersDefaults to stunt the user from hitting it more than once?
Instead of calling saveInBackground(), you'd better call the method saveInBackgroundWithBlock: instead. So the strategy is very simple:
First of all, define a 'busy' flag for the object (For example: savingInBackground) and store it wherever you like ( If you are showing 1 item then simply declare a Bool property / If you are showing a list of Item then declare a Dictionary with format ["objectID/Index": Bool]). This flag should be set to true for the item being saved in the background.
Whenever use taps on a Like button
If current item's savingInBackground flag is true, then do nothing
Else:
Set item's savingInBackground to true
Increase Like count and Call saveInBackgroundWithBlock:
In the completion block of saveInBackgroundWithBlock:, set savingInBackground back to false.
I am on train now so I can't write example code, but I hope that it's clear enough to help you to achieve what you want.

Creating an interactive Google Earth Tour (multiple tours)

I'm creating a Google Earth tour and I'd really like to be able to make this interactive so users can choose where they go.
I was thinking I could create each "scene" as a separate tour each ending with a decision (most likely through a placemark with a balloon containing a question and links for each possible answer).
However I'm having difficulties finding a way to load the next tour like this. Each tour will be available in a KMZ format and I'm open to if the new tour should be loaded from within the existing tour or from an external eventListener in the Google Earth API.
Any help or pointers would be gratefully received.
Dave
I presume you have already worked out how to play a tour using the plugin.If not, check this link
then you need to open a balloon at the end of each tour, which is two steps. Determine when the tour is ended, and then open a balloon which has a button or buttons to choose next tour.
To determine if the tour has ended use this function
function checkTour() {
// checks to see if it can read the time of the tour
// if it can it completes rest of function
try {
var duration = ge.getTourPlayer().getDuration();
var cTime = ge.getTourPlayer().getCurrentTime();
} catch (e) {
alert('error');
return false;
}
if (duration == cTime) {
// tour is over
tourOverSoOpenBalloonFunction();
} else {
// wait 1 second and check again
setTimeout('checkTour()',1000);
}
}
then use this example page of creating a balloon with a button in it that executes some javascript to load the next tour
essentially you would be changing this line
balloon.setContentString(
'Alert!');
to
balloon.setContentString(
'Tour 1<br/>Tour 2');
I might have missed something, but this should get you going in the right direction