TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Day 22 - Challenge 3 (linked to project 2)

Forums > 100 Days of Swift

Hi everyone,

I am stuck on the last part of this challenge: "Go back to project 2 and add a bar button item that shows their score when tapped."

I was able to create a leftBarButtonItem to display the score but it won't update when the actual score is changed - it stays at its initial value of 0. Do you have an idea how to make it update?

Here is what I have done so far:

override func viewDidLoad() {
    super.viewDidLoad()

    navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Score \(getScore())", style: .plain, target: self, action: #selector(getScore))

and:

@objc func getScore() -> Int {
    return score
}

Here I have made a getScore function because using score directly or through another property did not work. But that is not the solution either.

I would appreciate any help, so thanks in advance!

3      

Though your effort is admirable, I think that you went quite too far here :)

Your task here is to show the score simply by a UIVIewController, whether it would be an Alert or Activity one. Since the whole topic of Project 3 was the UIActivityViewController, I used that to show the score (with additional possibility of sharing it wherever I want).

So you don't have to worry about creating additional functions and stuff. Just use UIActivityViewController, where you will show your score using 'score' property, like this:

"Score: \(score)"

Let me know if that helps!

3      

Hello MateusZ,

Thanks for your response.

I was indeed in the wrong path! I have now solved the issue with a UIActivityViewController as you suggested.

Thank you for your help!

3      

Hacking with Swift is sponsored by Blaze.

SPONSORED Still waiting on your CI build? Speed it up ~3x with Blaze - change one line, pay less, keep your existing GitHub workflows. First 25 HWS readers to use code HACKING at checkout get 50% off the first year. Try it now for free!

Reserve your spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.