Ok, I have other view controllers that don't have any code connected to them. The only other part of code is loading a form. All the code I have is there.
Post
Replies
Boosts
Views
Activity
would you like the rest of the code, the project or a screenshot of the storyboard?
Here you go:
import UIKit
class Categories: UIViewController {
@IBOutlet weak var CategoryList: UITableView!
let names = [
"Dad Jokes",
"Virtual Assistant Jokes",
"Knock Knock Jokes"
]
override func viewDidLoad() {
super.viewDidLoad()
CategoryList.delegate = self
CategoryList.dataSource = self
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let backItem = UIBarButtonItem()
backItem.title = "Back"
navigationItem.backBarButtonItem = backItem // This will show in the next view controller being pushed
}}
extension Categories: UITableViewDelegate {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print(indexPath.row)
let row = indexPath.row
if row == 0 {
self.performSegue(withIdentifier: "Dad Jokes", sender: self)
}else if row == 1 {
self.performSegue(withIdentifier: "Assistant Jokes", sender: self)
}else if row == 2 {
self.performSegue(withIdentifier: "Knock Knock Jokes", sender: self)
}
tableView.deselectRow(at: indexPath, animated: true)}
}
extension Categories: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) - Int {
return names.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) - UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.text = names[indexPath.row]
return cell
}
}
Could you give an example?
Thank you so much for your help!
Where would I put that?
Thanks, but now the nineThirtyToday print is printing:
Nine Thirty Output Optional(2021-03-10 17:30:00 +0000)
Which is 5:30pm. Any ideas?
I want it to be if before 9:30 on Wednesdays it says waiting for server to update. However it prints nil and crashes when I force unwrap it.
I did a full reset and fixed it
Thank you for your patience with me and sorry for the misunderstanding, I am new to swift and just didn't see it. However it is working now and I am very grateful!
”!=“ is not, right? Thats what I have learned.
Thanks, but as you can see it says not nil, other ideas?
This is the most up to date code
import SafariServices
import WebKit
import FirebaseFirestore
import Firebase
class TheRiddle: UIViewController {
@IBOutlet weak var leading_TheRiddle: NSLayoutConstraint!
@IBOutlet weak var trailing_TheRiddle: NSLayoutConstraint!
@IBOutlet weak var CurrentRiddle: UILabel!
@IBOutlet weak var PreviousRiddle: UILabel!
var menuOut = false
override func viewDidLoad() {
super.viewDidLoad()
let db = Firestore.firestore()
print("TheRiddle collection: ", db.collection("TheRiddle").document("Riddles"))
db.collection("TheRiddle").document("Riddles").addSnapshotListener { snapshot, error in
//check for error
if error == nil {
//check if document exists
if snapshot != nil {
}else {
if let currentRiddle = snapshot?["CurrentRiddle"] as? String {
self.CurrentRiddle.text = "This Weeks Riddle: " + currentRiddle
print(currentRiddle)
}
if let previousRiddle = snapshot?["CurrentRiddle"] as? String {
self.PreviousRiddle.text = "Previous Riddle: " + previousRiddle
}
}
}
}
//db.collection("test").addDocument(data: ["hi":"bye"])
}
@IBAction func RiddleAnswerForm(_ sender: Any) {
let vc = SFSafariViewController(url: URL(string: "https://forms.office.com/Pages/ResponsePage.aspx?id=ytAqTDte6UK-KD5v_kOm4Y843IzqmYtFlDtLrfRYsi1UMFpUMk1GN01GS05BVFlJUElONk4yR1hKUCQlQCN0PWcu")!)
present(vc, animated: true)
}
@IBAction func menuTappedTheRiddle(_ sender: Any) {
if menuOut == false {
leading_TheRiddle.constant = 150
trailing_TheRiddle.constant = -150
menuOut = true
}
else {
leading_TheRiddle.constant = 0
trailing_TheRiddle.constant = 0
menuOut = false
}
UIView.animate(withDuration: 0.2, delay: 0.0, options: .curveEaseIn, animations: {
self.view.layoutIfNeeded()
}) { (animationComplete) in
print("The animation is complete")
}
}
}
Update, it is connected but I am not using the correct code. What code would i use to get the data of a specific data?
I don't think my app is connected to Firestore, how would I double check this?