Hello to all.....I am not totally new to programming but I am not that experienced so please be gentle !
I am developing a program, part of which has two sliders in a UI and a result text box. When the sliders are moved the result box is update as a result of a mathematical operation on the slider values (basically result = slider1 value * slider2 value) although it's a bit more involved than just multiplication...
I've been learning swift 4 / xcode 9 mostly for iOS since there are more tutorials but I want the program thi for desktop. This is my iOS code which works fine. When I use it in OS X (making necessary changes of UISlider to NSSlider, text to textString etc) it gives all host of errors :\
thank you in advance
I am developing a program, part of which has two sliders in a UI and a result text box. When the sliders are moved the result box is update as a result of a mathematical operation on the slider values (basically result = slider1 value * slider2 value) although it's a bit more involved than just multiplication...
I've been learning swift 4 / xcode 9 mostly for iOS since there are more tutorials but I want the program thi for desktop. This is my iOS code which works fine. When I use it in OS X (making necessary changes of UISlider to NSSlider, text to textString etc) it gives all host of errors :\
thank you in advance
Code:
import UIKit
class ViewController: UIViewController {
let carbStep: Float = 5
let flowStep: Float = 25
var volumeContraction: Float = 0
//carbonyl controls
@IBOutlet weak var carbSlider: UISlider!
@IBOutlet weak var carbValue: UILabel!
@IBOutlet weak var flowSlider: UISlider!
@IBOutlet weak var flowValue: UILabel!
@IBOutlet var nickelPerDay: UITextField!
func initialiseResult(){
volumeContraction = (2500/(2500+(3*carbSlider.value))) // works in iOS error in OS X
nickelPerDay.text = "\(Int(flowSlider.value*carbSlider.value*volumeContraction*(24/1000000)))"
}
@IBAction func sliderValueChanged(_ sender: UISlider) {
let roundedCarbValue = round(sender.value / carbStep) * carbStep
sender.value = roundedCarbValue
carbValue.text = "\(Int(sender.value))"
nickelPerDay.text = "\(Int(flowSlider.value*carbSlider.value*volumeContraction*(24/1000000)))"
}
@IBAction func flowValue(_ sender: UISlider) {
let roundedFlowValue = round(sender.value / flowStep)*flowStep
sender.value = roundedFlowValue
flowValue.text = "\(Int(sender.value))"
nickelPerDay.text = "\(Int(flowSlider.value*carbSlider.value*volumeContraction*(24/1000000)))"
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//define some variables
self.initialiseResult ()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}