send indexpath to Firebase (like button)

send indexpath to Firebase (like button)

By : Joe.kramer
Date : November 21 2020, 03:00 PM
it helps some times Okay so I spent an hour or so to just give you an idea how you can do what you need to do. Liking and unliking from your custom UITableViewCell. I've explained in each line of code I made the details. I hope this helps you out. Let me know if you have questions. Remember this is just one of the many ways you can do your task.
code :
class MyViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, MyCustomCellDelegate {

    // This is the array of keys that we
    var likedDataKeys = [String]()

    override func viewDidLoad() {

        // Load here the 'Likes' stuff and store its in a datasource for reference or store as well its keys.
        // If data is liked, store to likedDayaKeys the key of your data.

        FirebaseCall {
            if liked {

    // MARK: - UITableViewDataSource

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = ....

        // Set the image.

        let dataKey = yourDatasource[indexPath.row] // get the key or whatever data you need

        // Set the delegate and key
        cell.delegate = self
        cell.dataKey = dataKey

        if likedDataKeys.contains(dataKey) {
            cell.image = redImageLike
        } else {
            cell.image = whiteNormalLikeImage

        return cell

    // MARK: - MyCustomCellDelegate

    func myCustomCell(userDidTapLikeWithDataKey dataKey: String) {
        // So now we can get the dataKey of the cell that is being liked or unliked.
        // Check from the self.likedDataKeys if the tapped cell is liked or not.

        if self.likedDataKeys.contains(dataKey) {
            // If it is there, then we should call the unlike Firebase.
            // Also remove it from the self.likedIndexPath and reload the tableView to update the image.

            let index = self.likedDataKeys.index(of: dataKey)
            self.likedDataKeys.remove(at: index)

            // Call now the unlike Firebase.

        } else {
            // If it is not there, then we should call the like Firebase.
            // Also store it to the self.likedIndexPAth
protocol MyCustomCellDelegate: NSObjectProtocol {
    // This is the delegate that will help us send the dataKey reference to the viewController
    // Whenever the user taps on the like button in the cell.
    func myCustomCell(userDidTapLikeWithDataKey dataKey: String)

class MyCustomCell: UITableViewCell {

    // This will be called in the viewController, pass here the self of the viewController
    weak var delegate: MyCustomCellDelegate?

    // Make sure to pass here the key from the cellForRow of the viewController's tableView delegate.
    var dataKey = ""

    @IBAction func LikeClicked(_ sender: UIButton) -> Void {
        // Call the delegate to inform the viewController
        self.delegate?.myCustomCell(userDidTapLikeWithDataKey: self.dataKey)

Share : facebook icon twitter icon
Delete Firebase Data located at indexPath.row

Delete Firebase Data located at indexPath.row

By : Daniel Marius
Date : March 29 2020, 07:55 AM
will help you Been trying to figure this out for a while and I cannot understand why this keeps crashing. I swipe the cell and the delete button shows up, but when pressed it crashes at: , I found an easier way of doing this. In your post method:
code :
//Create a random string for you child:
NSString *uuid = [NSUUID UUID].UUIDString;

//Put the random string as one of your childs:
[[[_alertRef child:@"posts"] child:uuid] setValue:@{ 

//create a key called childID and assign it the same value:
@"childID" : uuid, 
@"date" : _date, 
@"description" : _descriptionTextView.text, 
@"title" : _alertTitle.text }];
- (void)getUpdates {
    posts = [_datRef child:@"posts"];
    [[posts queryOrderedByChild:@"date"] observeEventType:FIRDataEventTypeValue
                                                withBlock:^(FIRDataSnapshot *snapshot) {
                                                  self.updatesArray = [NSMutableArray array];
                                                  for (snapshot in snapshot.children) {
                                                      [self.updatesArray addObject:snapshot];
                                                      _firebaseDict = [[NSDictionary alloc] init];
                                                      _firebaseDict = snapshot.value;
                                                      _sortArray = [updatesArray reverseObjectEnumerator].allObjects;
                                                      self.finalArray = [NSMutableArray array];
                                                      [self.finalArray addObjectsFromArray:_sortArray];
                                                  [self.tableView reloadData];
    [self.tableView reloadData];
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        NSString *childID = [_firebaseDict valueForKey:@"childID"];
        [[[_datRef child:@"posts"] child:childID] removeValue];
        [finalArray removeObjectAtIndex:indexPath.row];

        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
i want to send an location updates to Firebase when the user Clicks on a button

i want to send an location updates to Firebase when the user Clicks on a button

By : Melvin Htet Aung Hei
Date : March 29 2020, 07:55 AM
I hope this helps you . Where you initialize LocationManager loc; ? It is never initialised as per your code that's why you are getting null pointer exception.
Something wrong with my Array's IndexPath? swift 4 Firebase

Something wrong with my Array's IndexPath? swift 4 Firebase

By : Caleb
Date : March 29 2020, 07:55 AM
will help you First, using the sender might be confusing; typically sender would be the one who caused the event, not an arbitrary data being transported.
I would improve your code using this:
code :
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    performSegue(withIdentifier: "CommentSegue", sender: tableView)
    // ...

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

    if segue.identifier == "CommentSegue"{
        guard let commentVC = segue.destination as? CommentViewController else { return }
        guard let tableView = sender as? UITableView else { return }
        guard let selectedRow = tableView.indexPathForSelectedRow?.row else { return }

        let post =  posts[selectedRow]
        print("Selected: \(post)")
        commentVC.post = post
func loadData() {
    postKey = post["key"] // or something else, you'll need to fetch the data base key from the current dictionary
    Database.database().reference().child("posts").child(postKey).observeSingleEvent(of: .value) { (snapshot) in
        if let dict = snapshot.value as? [String: AnyObject] {
            self.titeLabel.text = dict["title"] as? String
I can not send the text to firebase when Button is click with redux

I can not send the text to firebase when Button is click with redux

By : user676852
Date : March 29 2020, 07:55 AM
I wish this helpful for you
You are not passing a text variable into your onSendButtonPressed function. It looks like you should be calling it using the following syntax:
How to split indexPath array into seperate array of indexPath, each array's indexPath has same indexPath.section

How to split indexPath array into seperate array of indexPath, each array's indexPath has same indexPath.section

By : Teotihuacan Mexico
Date : March 29 2020, 07:55 AM
it helps some times One possible solution is to first build a dictonary where the keys are the section numbers and the values are the array of IndexPath in that section.
code :
let indexPaths = [
    IndexPath(row: 0, section: 1),
    IndexPath(row: 1, section: 1),
    IndexPath(row: 2, section: 1),
    IndexPath(row: 2, section: 0),

let pathDict = Dictionary(grouping: indexPaths) { (path) in
    return path.section
let sectionPaths = pathDict.sorted { (arg0, arg1) -> Bool in
    return arg0.key < arg1.key // sort by section
}.map { $0.value } // get just the arrays of IndexPath

Related Posts Related Posts :
  • Managing cookies for a domain in Associated Domains
  • Array items showing error in IOS
  • Saving asynchronously downloaded files' contents to SQLITE
  • Swift 4 - animating both alpha and constraint affects other components alpha value
  • UIView animation in completion block starts with displacement
  • List all Apps and Track Internet Usage
  • Handling Back To Back HTTP Posts SWIFT 4.0
  • Azure App Service Push - registration endpoint
  • Select multiple item in a tableView
  • Apartment number / Unit number returned from google places api
  • How to align UICollectionViewCells from left to right?
  • How can I add search option on UIPickerview in ios?
  • Scenekit - physicsWorld setup to prevent kinematic nodes to intersect
  • Carthage Build Failed
  • swift 3, ios 10 - push notification firebase is not received
  • App Xcode 8 to Xcode 9 - Prevent Auto Hide Status Bar
  • How to pop back to a TableViewController?
  • Is UserDefaults thread safe in Swift? How to check it?
  • UISwitch in a table selects multiple cells when switch state on
  • iOS App with no story board (Size classes and Device type limitations)
  • AudioKit issue, mic not sensitive enough
  • UIColor saturation brightness values different from the regular saturation luminosity values of a color
  • JSON: Extracting Data Using Alamofire and Swift 3
  • invalid_grant on OAuth2 request when obtaining access_token from SSO in App
  • ABNewPersonViewController using contact framework
  • Design iOS button scalable
  • Subclassing NSLayoutConstraint constant based on screen height
  • Migrate Realm 2.x List of Object to Realm 3.x List of String (or other primary type)
  • Using BLE RSSI value for connect-by-proximity
  • Backgroundcolor of NSTextfield
  • Firebase modifying uid in every view
  • How to rotate orientation?
  • Upload a new version of ios app to app store?
  • UIScrollView do not scroll down to its original position when keyboard disappear
  • What is the most effective way of tracking time/dates in an iOS/Swift application?
  • WatchKit get user's preferred handedness
  • Location permission dialog is shown and immediately disappears
  • Combine these regex expressions
  • How to save an array of HKQuantitySamples (heart rate) to a workout
  • RestKit mapping with parent key as attribute and key contains parenthesis
  • How to add UITextField programmatically to UIScrollView without breaking constraints?
  • How to make a view height grow depending on its child views contents
  • Some users experiencing NSInternalInconsistencyException crash
  • Mark successful siesta response as error
  • Using a modified PDFTron Tools Framework
  • How can I use universal links when I call openURL inside my own app?
  • NSArray of doubles iOS (Objective c)
  • Passing data from embedded PageViewController to parent View Controller
  • Reuse item inside a row when scrolling
  • Realm Relation how to implement
  • error: generic parameter 'T' could not be inferred in swift
  • Adding shadow to UITextView makes text expand out of UITextViewFrame
  • How to change the string in seconds to minutes in Swift3?
  • Search bar is refreshing the index of my table view cell
  • Decodable multiple DateDecodingStrategies
  • The spoiled simulator xcode 9. As a broken TV
  • How to set width of TouchableWithoutFeedback depends on Text in react-native?
  • How to show an UIActivityIndicatorView whitin UITableViewController?
  • UItextfield text in Custom UITableViewCell prints nil when i scroll up in SE
  • How to append or add multiple items to an array in Swift 4
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org