0

I need really help with making the logic here, so I've got 3 different arrays that I use in my UIPickerView .when user selects something like this in a pickerview a certain formula should execute (its not relevant which it is) what should I use? if statements? switch? and one more question. will the shiftCount array data that is used as string be a problem? Because I need to then multiply the formula by *1 or *2 and etc.

   var shiftCount = [
   "1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25"]

   var Level = [
       "White","Silver 80%","Silver 100%","Gold 80%","Gold 100%","Diamond 80%","Diamond 100%",]

   var shiftDay = [

   "MNG","LMNG","AFT","LAFT","PEAK","LNGT","NGT"]
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {


        switch (component) {
        case 0:
            MyShifts = shiftCount[row]
            shifts.text = "How many shifts: " + MyShifts
            print(MyShifts)
        case 1:
            MyShiftType = shiftDay[row]
            shiftType.text = "Shift you work: " + MyShiftType
            print(MyShiftType)
        case 2:
            MyLevel = Level[row]
            level.text = "Your Level: " + MyLevel
            print(MyLevel)
        default:
            break
        } 
Ravi B
  • 1,574
  • 2
  • 14
  • 31
  • like to be more precise , with what ever option user will select in component[1] or component[2] i need to execute a formula . component[0] is just for multiplying that formula x1 x2 x3 times . what ever user selects. –  Swift newbie Jul 17 '19 at 11:14
  • Edit your question instead of posting comments to it.Could you clarify your question by using some better syntax like starting a new sentence with an uppercase letter and not throwing in question marks everywhere. – Joakim Danielson Jul 17 '19 at 11:46

1 Answers1

0

The if statements are recommended for when you have only two options to evaluate, so in this case the switch statement it's ok, regarding your second question about the string arrays being a problem when you want to apply your formula it won't be a problem, but You will need to be converting that string to Int, Double, Float or whatever type You'll need to do your math, and if you want to show that on a label or something like that you can do string interpolation to show it.

Samuel Chavez
  • 768
  • 9
  • 12