liko
liko

Reputation: 3

Calculation with Multiple Parameters

(New to coding in general, sorry if Im not using right language/logic)

Im trying to make a calculator app for online sales that would allow you to see how much money you would get after fees from different websites. I used a UIPickerView for the selling platforms where the user can select which website they want to sell on which then outputs to a UITextField. Next is a UIPickerView for the seller level within the selling platforms that then links to another UITextField (seller levels dictate the fee %, higher levels mean lower fees).

So far I haven't been able to create multiple criteria so that when platform = x and seller level = y then it would spit out the value of an equation. When I did this in excel it was with if & and based functions for example: if(and(platform = "StockX, seller level = 1),(List Price * (1-0.125),""). Obviously swift is not excel so this is where I am stuck.

[sorry added code below, not quite sure if this would be everything you would need to diagnose the problem but any direction is welcomed, thank you!]

import UIKit

class ViewControllerTakeback: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource, UITextFieldDelegate {

var currentTextField = UITextField()
var pickerView = UIPickerView()
var levelTextField = UITextField()
var levelPickerView = UIPickerView()

var PlatformType:[String] = []
var Platform2Type:[String] = []
var PLevel:[String] = []
var PLevel2: [String] = []

//variables for criteria on the takeback calculation
var a = "StockX", b = "GOAT", c = "Stadium Goods", d = "Flight Club", e = "Grailed", f = "PayPal"
var aa = "1", bb = "2", cc = "3", dd = "4", ee = "Domestic", ff = "International", gg = "Invoice"

//text fields
@IBOutlet weak var platformTextField: UITextField!
@IBOutlet weak var platformTextField2: UITextField!
@IBOutlet weak var pLevelTextField: UITextField!
@IBOutlet weak var pLevel2TextField: UITextField!
@IBOutlet weak var takebackLabel: UILabel!
@IBOutlet weak var retailTextField: UITextField!

override func viewDidLoad() {
    super.viewDidLoad()
//data for platformTextField & platformTextField2 via pickerView
PlatformType = ["StockX","GOAT","Stadium Goods","Flight Club","Grailed","PayPal"]
Platform2Type = ["StockX","GOAT","Stadium Goods","Flight Club","Grailed","PayPal"]

//data for pLevelTextField & pLevel2TextField via pickerView
PLevel = ["1","2","3","4","5","Domestic","International","Invoice"]
PLevel2 = ["1","2","3","4","5","Domestic","International","Invoice"]
}

also attached an image of the app to see how the flow works. Ideally id like to have it so that you can pull info from two different websites and compare which one would be better to sell on.

app view app view annotated

Upvotes: 0

Views: 134

Answers (3)

DevKyle
DevKyle

Reputation: 1091

Sounds like switch might be useful for you. Below is an example for how this might work in your case. Note that <platform> and <seller lever> would be replaced with the actual variables you have declared.

switch(<platform>, <seller level>)
{
  case ("StockX", 1):
      //price equation
  case ("StockY", 2):
      //price equation
  default:
      //price equation
}

Upvotes: 1

matt
matt

Reputation: 535617

Actually the way you were doing this in Excel would work in Swift too (a big IF or switch). But it would be way cooler and Swiftier to have a lookup table where you can input the platform and level and fetch out the multiplier or even a multiplier function (since functions are first class citizens in Swift).

Upvotes: 0

Loren Rogers
Loren Rogers

Reputation: 359

If I am understanding your problem correctly I would create some containers. A container (array or dictionary) for the seller-level->fee, One for website->Not-sure-in-your-example. Then you can create the UIPickerView items from these containers and use the prescribed numbers attached to containers for you calculation

Upvotes: 0

Related Questions