1

For filling the Progress Bar, there're 2 objects connected to ViewController.swift file.

@IBOutlet var progBar: UIProgressView!

@IBAction func butPressed(sender: UIButton) {
self.progBar.progress += 0.1

But when I try to read the value of the bar has with the way below, nothing happens. Except the following message :

value <UIProgressView: 0x7ff85bd9eb00; frame = (85 128; 146 2); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x7ff85bd9ee70>>

println ("The value is \(progBar)")

How to solve that?

Victor Sigler
  • 23,243
  • 14
  • 88
  • 105

2 Answers2

1

You need to keep a variable to store the value of the progress view. The progress view is just for displaying not for storing.

This is a fundamental MVC pattern - the view should not be the data store.

Mundi
  • 79,884
  • 17
  • 117
  • 140
  • Though the view should not be the datasource, you are allowed to ask for its current state which in this case is provided by the progress property of a UIProgressView. – Jeremy Pope Feb 16 '15 at 20:24
  • You are referring to special cases to facilitate *changing* the view based on certain view properties. If you need to ask your view for a state for your application logic to work, you have a flawed design. – Mundi Feb 16 '15 at 20:35
0

UIProgressView has a property called progress which is a float between 0 and 1. If you are wanting to print it, you just need to access it instead of the whole view.

println("The value is \(progBar.progress)")

You do not need to create another variable to hold this information.

Jeremy Pope
  • 3,342
  • 1
  • 16
  • 17