This repository was archived by the owner on Nov 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddDeleteClubsOrgsTableViewCell.swift
More file actions
57 lines (46 loc) · 1.99 KB
/
AddDeleteClubsOrgsTableViewCell.swift
File metadata and controls
57 lines (46 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//
// AddDeleteClubsOrgsTableViewCell.swift
// MUnchMates
//
// Created by Michael Ulrich on 1/30/18.
// Copyright © 2018 Michael Ulrich. All rights reserved.
//
import UIKit
import Firebase
// class for cell in tableView for AddDeleteClubsOrgsViewController
class AddDeleteClubsOrgsTableViewCell: UITableViewCell {
// variables
var uid = Auth.auth().currentUser?.uid
var cellClubOrgId:String?
var viewControllerId = "AddDeleteClubsOrgsVC"
// outlets
@IBOutlet weak var lblClubsOrgs: UILabel!
@IBOutlet weak var switchClubsOrgs: UISwitch!
// ACTION: toggling switches to add/delete club/org
@IBAction func switchToggleClubsOrgs(_ sender: Any) {
// put club/org name and id into variables
let clubsOrgsNameValue = self.lblClubsOrgs.text
let clubsOrgsIdValue = self.cellClubOrgId!
// structure is used to store clubsOrgsName and clubsOrgsId. when switch is toggled, this structure gets saved or deleted from user's clubsOrgs node in the Firebase Database.
let clubsOrgsValues:[String:Any] =
[
"clubsOrgsName":clubsOrgsNameValue,
"clubsOrgsId":clubsOrgsIdValue
]
// if switch is on, clubOrg gets added to user's clubsOrgs node in database. if switch is toggled off, clubOrg gets deleted from user's clubsOrgs node in database.
if (sender as AnyObject).isOn == true {
Database.database().reference().child("USERS/\(uid!)/clubsOrgs/\(clubsOrgsIdValue)").setValue(clubsOrgsValues)
}
else {
Database.database().reference().child("USERS/\(uid!)/clubsOrgs/\(clubsOrgsIdValue)").removeValue()
}
}
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}