Mzochi Mzochi - 4 years ago 126
Swift Question

using an array in Swift

I'm trying to change the action of CallCamp button depending on a pickerView.selectedRow in another ViewController, so here is my code:

@IBAction func CallComp(_ sender: UIButton) {
let PickerRows = self.storyboard?.instantiateViewController(withIdentifier: "firstViewController") as? firstViewController




func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)

{ let r1 = pickerView.selectedRow(inComponent:0)
let r2 = pickerView.selectedRow(inComponent: 1)
let r3 = pickerView.selectedRow(inComponent: 2)
var rows = [r1,r2,r3]

switch rows {
case r1:

if let phoneCallURL:NSURL = NSURL(string: "tel://\(990)") {
let application:UIApplication = UIApplication.shared
if (application.canOpenURL(phoneCallURL as URL)) {
application.openURL(phoneCallURL as URL);
}}



case r2:

if let phoneCallURL:NSURL = NSURL(string: "tel://\(900)") {
let application:UIApplication = UIApplication.shared
if (application.canOpenURL(phoneCallURL as URL)) {
application.openURL(phoneCallURL as URL);
}}




default:
if let phoneCallURL:NSURL = NSURL(string: "tel://\(999)") {
let application:UIApplication = UIApplication.shared
if (application.canOpenURL(phoneCallURL as URL)) {
application.openURL(phoneCallURL as URL);
}
}

}}}


then I got two errors in the lines :
case r1:
,
case r2:


the error syntax:


expression pattern of type 'int' cannot match values of type '[int]'


so any help would be useful, thanks

Answer Source

rows is defined as an array of Int, and your switch cases are Int

You're not actually doing anything based on the pickerView selection - have you tried working through some pickerView tutorials?

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