Ahmet Celal Küpeli Ahmet Celal Küpeli -4 years ago 136
Swift Question

IOS Save Label data

i know its asked too many times but i tried all examples and still im stuck
i dont know what im gonna do.. im inserting sample code inside still im getting error there is the code without NS is counting the taps end of game i wanna save the tap. when player start the game i wanna load last value of tap also i need help for clear taps..

//Score Counting button
var count : Int = 0
@IBAction func ButtonA(sender: AnyObject) {
//Score counting
count += 1
Score.text = String(count) }

@IBOutlet weak var Score: UILabel! //this is the taps numbers
@IBOutlet weak var ScoreInfo: UITextField!

im a begginer pls dont hit hard :)

Answer Source

Can you be more specific with your problem? Part of getting help is asking the right question. Some things that come to mind:

  1. Are your @IB Outlets and Action properly connected to their components in the storyboard?

  2. When you say "the player start the game", does that mean you want the data to persist on each app launch? If so, then you will need to use some type of database such as CoreData or Realm to persist your data. If this isn't the case, then you should be fine as count will persist in whatever ViewController is holding it.

  3. Your object variable names look like they're subclassing the UILAbel and UITextfield classes. I recommend you camel case (i.e. score, scoreInfo, buttonA) your variable names.

  4. Also not sure what you're trying to use the textfield for. Label will be sufficient like you've done already.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download