App crashes when button tapped with testflight












0















I'm developing app with Swift 4.2 and I have problems with iOS app crash.
For me everything works fine, but it doesn't work for others who installed app with testflight.
Error is like this.
enter image description here



Here's a code that adds handler.



cell.btnBooknow.addTarget(self, action: #selector(pressBookNowButton(button:)), for: .touchUpInside)


Here is a button click handler.



@objc func pressBookNowButton(button: UIButton) {
guard let tagValue = self.arrListingBagHandler.object(at: button.tag) else {
return
}
print(self.artworks)

print(self.onlineStatus)
print(self.arrSearchAddressResult)


print(tagValue)
let valueStatus = tagValue["IsOnline"] as! String
let availability = tagValue["AvailabilityDays"] as! String
let arr = Array(availableDays)
print(valueStatus)
print(arr)
let arrAvailability = Array(availability)
print(arrAvailability)
let arr1 = availability.components(separatedBy: ",")
print(arr1)

let day = (presentDay!-1)
let today = "(day)"
print(today)
if arr1.contains(today)
{
availableToday = true
}
else
{
availableToday = false
}

if valueStatus == "1" && availableToday == true
{
let obj = self.storyboard?.instantiateViewController(withIdentifier: "bookingId") as! BookingViewController
obj.dicBagHanlderDetail = tagValue
self.navigationController?.pushViewController(obj, animated: true)
}
else
{
let alert = UIAlertController(title: "Alert!", message: "You can't make booking because store is currently closed.", preferredStyle: .alert)
let okAction = UIAlertAction(title: "OK", style: .cancel) { (actoin) in
}
alert.addAction(okAction)
self.present(alert, animated: true, completion: nil)
}

}


Can anyone please help me?
Thanks.










share|improve this question




















  • 2





    Sharing the code of that method might help. Also, you could try to install the release version on your phone.

    – Larme
    Jan 3 at 11:36











  • Yes, for me it's working, but on the client's phone, it crashes.

    – ZhengGe Che
    Jan 3 at 11:37






  • 2





    It crashed on a iOS 12.1 iPhone 6 Plus. Can you try that in this configuration? Also, we can't guess what's wrong without code.

    – Larme
    Jan 3 at 11:38






  • 1





    @ZhengGeChe at first line you try to force conversion to [ string : Any ] will you please use guard let

    – chirag shah
    Jan 3 at 11:43






  • 1





    Copy paste code, not screenshot of code. Any use of ! is a potential reason of crash. Use if let or guard let, don't force unwrap. Also if you install it yourself through TestFlight, can you reproduce the crash?

    – Larme
    Jan 3 at 11:46


















0















I'm developing app with Swift 4.2 and I have problems with iOS app crash.
For me everything works fine, but it doesn't work for others who installed app with testflight.
Error is like this.
enter image description here



Here's a code that adds handler.



cell.btnBooknow.addTarget(self, action: #selector(pressBookNowButton(button:)), for: .touchUpInside)


Here is a button click handler.



@objc func pressBookNowButton(button: UIButton) {
guard let tagValue = self.arrListingBagHandler.object(at: button.tag) else {
return
}
print(self.artworks)

print(self.onlineStatus)
print(self.arrSearchAddressResult)


print(tagValue)
let valueStatus = tagValue["IsOnline"] as! String
let availability = tagValue["AvailabilityDays"] as! String
let arr = Array(availableDays)
print(valueStatus)
print(arr)
let arrAvailability = Array(availability)
print(arrAvailability)
let arr1 = availability.components(separatedBy: ",")
print(arr1)

let day = (presentDay!-1)
let today = "(day)"
print(today)
if arr1.contains(today)
{
availableToday = true
}
else
{
availableToday = false
}

if valueStatus == "1" && availableToday == true
{
let obj = self.storyboard?.instantiateViewController(withIdentifier: "bookingId") as! BookingViewController
obj.dicBagHanlderDetail = tagValue
self.navigationController?.pushViewController(obj, animated: true)
}
else
{
let alert = UIAlertController(title: "Alert!", message: "You can't make booking because store is currently closed.", preferredStyle: .alert)
let okAction = UIAlertAction(title: "OK", style: .cancel) { (actoin) in
}
alert.addAction(okAction)
self.present(alert, animated: true, completion: nil)
}

}


Can anyone please help me?
Thanks.










share|improve this question




















  • 2





    Sharing the code of that method might help. Also, you could try to install the release version on your phone.

    – Larme
    Jan 3 at 11:36











  • Yes, for me it's working, but on the client's phone, it crashes.

    – ZhengGe Che
    Jan 3 at 11:37






  • 2





    It crashed on a iOS 12.1 iPhone 6 Plus. Can you try that in this configuration? Also, we can't guess what's wrong without code.

    – Larme
    Jan 3 at 11:38






  • 1





    @ZhengGeChe at first line you try to force conversion to [ string : Any ] will you please use guard let

    – chirag shah
    Jan 3 at 11:43






  • 1





    Copy paste code, not screenshot of code. Any use of ! is a potential reason of crash. Use if let or guard let, don't force unwrap. Also if you install it yourself through TestFlight, can you reproduce the crash?

    – Larme
    Jan 3 at 11:46
















0












0








0








I'm developing app with Swift 4.2 and I have problems with iOS app crash.
For me everything works fine, but it doesn't work for others who installed app with testflight.
Error is like this.
enter image description here



Here's a code that adds handler.



cell.btnBooknow.addTarget(self, action: #selector(pressBookNowButton(button:)), for: .touchUpInside)


Here is a button click handler.



@objc func pressBookNowButton(button: UIButton) {
guard let tagValue = self.arrListingBagHandler.object(at: button.tag) else {
return
}
print(self.artworks)

print(self.onlineStatus)
print(self.arrSearchAddressResult)


print(tagValue)
let valueStatus = tagValue["IsOnline"] as! String
let availability = tagValue["AvailabilityDays"] as! String
let arr = Array(availableDays)
print(valueStatus)
print(arr)
let arrAvailability = Array(availability)
print(arrAvailability)
let arr1 = availability.components(separatedBy: ",")
print(arr1)

let day = (presentDay!-1)
let today = "(day)"
print(today)
if arr1.contains(today)
{
availableToday = true
}
else
{
availableToday = false
}

if valueStatus == "1" && availableToday == true
{
let obj = self.storyboard?.instantiateViewController(withIdentifier: "bookingId") as! BookingViewController
obj.dicBagHanlderDetail = tagValue
self.navigationController?.pushViewController(obj, animated: true)
}
else
{
let alert = UIAlertController(title: "Alert!", message: "You can't make booking because store is currently closed.", preferredStyle: .alert)
let okAction = UIAlertAction(title: "OK", style: .cancel) { (actoin) in
}
alert.addAction(okAction)
self.present(alert, animated: true, completion: nil)
}

}


Can anyone please help me?
Thanks.










share|improve this question
















I'm developing app with Swift 4.2 and I have problems with iOS app crash.
For me everything works fine, but it doesn't work for others who installed app with testflight.
Error is like this.
enter image description here



Here's a code that adds handler.



cell.btnBooknow.addTarget(self, action: #selector(pressBookNowButton(button:)), for: .touchUpInside)


Here is a button click handler.



@objc func pressBookNowButton(button: UIButton) {
guard let tagValue = self.arrListingBagHandler.object(at: button.tag) else {
return
}
print(self.artworks)

print(self.onlineStatus)
print(self.arrSearchAddressResult)


print(tagValue)
let valueStatus = tagValue["IsOnline"] as! String
let availability = tagValue["AvailabilityDays"] as! String
let arr = Array(availableDays)
print(valueStatus)
print(arr)
let arrAvailability = Array(availability)
print(arrAvailability)
let arr1 = availability.components(separatedBy: ",")
print(arr1)

let day = (presentDay!-1)
let today = "(day)"
print(today)
if arr1.contains(today)
{
availableToday = true
}
else
{
availableToday = false
}

if valueStatus == "1" && availableToday == true
{
let obj = self.storyboard?.instantiateViewController(withIdentifier: "bookingId") as! BookingViewController
obj.dicBagHanlderDetail = tagValue
self.navigationController?.pushViewController(obj, animated: true)
}
else
{
let alert = UIAlertController(title: "Alert!", message: "You can't make booking because store is currently closed.", preferredStyle: .alert)
let okAction = UIAlertAction(title: "OK", style: .cancel) { (actoin) in
}
alert.addAction(okAction)
self.present(alert, animated: true, completion: nil)
}

}


Can anyone please help me?
Thanks.







ios iphone swift






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 11:48







ZhengGe Che

















asked Jan 3 at 11:35









ZhengGe CheZhengGe Che

624822




624822








  • 2





    Sharing the code of that method might help. Also, you could try to install the release version on your phone.

    – Larme
    Jan 3 at 11:36











  • Yes, for me it's working, but on the client's phone, it crashes.

    – ZhengGe Che
    Jan 3 at 11:37






  • 2





    It crashed on a iOS 12.1 iPhone 6 Plus. Can you try that in this configuration? Also, we can't guess what's wrong without code.

    – Larme
    Jan 3 at 11:38






  • 1





    @ZhengGeChe at first line you try to force conversion to [ string : Any ] will you please use guard let

    – chirag shah
    Jan 3 at 11:43






  • 1





    Copy paste code, not screenshot of code. Any use of ! is a potential reason of crash. Use if let or guard let, don't force unwrap. Also if you install it yourself through TestFlight, can you reproduce the crash?

    – Larme
    Jan 3 at 11:46
















  • 2





    Sharing the code of that method might help. Also, you could try to install the release version on your phone.

    – Larme
    Jan 3 at 11:36











  • Yes, for me it's working, but on the client's phone, it crashes.

    – ZhengGe Che
    Jan 3 at 11:37






  • 2





    It crashed on a iOS 12.1 iPhone 6 Plus. Can you try that in this configuration? Also, we can't guess what's wrong without code.

    – Larme
    Jan 3 at 11:38






  • 1





    @ZhengGeChe at first line you try to force conversion to [ string : Any ] will you please use guard let

    – chirag shah
    Jan 3 at 11:43






  • 1





    Copy paste code, not screenshot of code. Any use of ! is a potential reason of crash. Use if let or guard let, don't force unwrap. Also if you install it yourself through TestFlight, can you reproduce the crash?

    – Larme
    Jan 3 at 11:46










2




2





Sharing the code of that method might help. Also, you could try to install the release version on your phone.

– Larme
Jan 3 at 11:36





Sharing the code of that method might help. Also, you could try to install the release version on your phone.

– Larme
Jan 3 at 11:36













Yes, for me it's working, but on the client's phone, it crashes.

– ZhengGe Che
Jan 3 at 11:37





Yes, for me it's working, but on the client's phone, it crashes.

– ZhengGe Che
Jan 3 at 11:37




2




2





It crashed on a iOS 12.1 iPhone 6 Plus. Can you try that in this configuration? Also, we can't guess what's wrong without code.

– Larme
Jan 3 at 11:38





It crashed on a iOS 12.1 iPhone 6 Plus. Can you try that in this configuration? Also, we can't guess what's wrong without code.

– Larme
Jan 3 at 11:38




1




1





@ZhengGeChe at first line you try to force conversion to [ string : Any ] will you please use guard let

– chirag shah
Jan 3 at 11:43





@ZhengGeChe at first line you try to force conversion to [ string : Any ] will you please use guard let

– chirag shah
Jan 3 at 11:43




1




1





Copy paste code, not screenshot of code. Any use of ! is a potential reason of crash. Use if let or guard let, don't force unwrap. Also if you install it yourself through TestFlight, can you reproduce the crash?

– Larme
Jan 3 at 11:46







Copy paste code, not screenshot of code. Any use of ! is a potential reason of crash. Use if let or guard let, don't force unwrap. Also if you install it yourself through TestFlight, can you reproduce the crash?

– Larme
Jan 3 at 11:46














2 Answers
2






active

oldest

votes


















0














Please use below function and resolve an issue. I think it is possible because of the force cast string and int value.



@objc func pressBookNowButton(button: UIButton) {
guard let tagValue = self.arrListingBagHandler.object(at: button.tag) else {
return
}




let valueStatus = tagValue["IsOnline"] as? String ?? ""
let availability = tagValue["AvailabilityDays"] as? String ?? ""
let arr = Array(availableDays)

let arrAvailability = Array(availability)

let arr1 = availability.components(separatedBy: ",")

let value : Int = Int(presentDay) ?? 0
let day = (value-1)
let today = "(day)"

if arr1.contains(today)
{
availableToday = true
}
else
{
availableToday = false
}

if valueStatus == "1" && availableToday == true
{
let obj = self.storyboard?.instantiateViewController(withIdentifier: "bookingId") as! BookingViewController
obj.dicBagHanlderDetail = tagValue
self.navigationController?.pushViewController(obj, animated: true)
}
else
{
let alert = UIAlertController(title: "Alert!", message: "You can't make booking because store is currently closed.", preferredStyle: .alert)
let okAction = UIAlertAction(title: "OK", style: .cancel) { (actoin) in
}
alert.addAction(okAction)
self.present(alert, animated: true, completion: nil)
}

}





share|improve this answer































    1














    As others suggested any ! is a potential crash. Try to replace it with guard or default values. For example you can change:



    let valueStatus = tagValue["IsOnline"] as! String
    let availability = tagValue["AvailabilityDays"] as! String


    To solution with default values:



    let valueStatus = tagValue["IsOnline"] as? String ?? "1"
    let availability = tagValue["AvailabilityDays"] as? String ?? "5"


    Or even better guard and e.g. display alert if data aren't available:



    guard let valueStatus = tagValue["IsOnline"] as? String,
    let availability = tagValue["AvailabilityDays"] as? String else {
    // Display alert in case of unavailable data (or simply return)
    let alert = UIAlertController(title: "Alert!", message: "You can't make booking because store is currently closed.", preferredStyle: .alert)
    let okAction = UIAlertAction(title: "OK", style: .cancel) { _ in }
    alert.addAction(okAction)
    self.present(alert, animated: true, completion: nil)
    return
    }
    // Continue as expected here...





    share|improve this answer





















    • 1





      Yeah, thats would work but will lead to wrong behaviour, which makes the user book wrongly. I think the crash happens cause the data return nil, so I think its good if he could debug why this return nil, maybe the way he is passing the tag from the cell.

      – Bassem Qoulta
      Jan 3 at 12:06













    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54021499%2fapp-crashes-when-button-tapped-with-testflight%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Please use below function and resolve an issue. I think it is possible because of the force cast string and int value.



    @objc func pressBookNowButton(button: UIButton) {
    guard let tagValue = self.arrListingBagHandler.object(at: button.tag) else {
    return
    }




    let valueStatus = tagValue["IsOnline"] as? String ?? ""
    let availability = tagValue["AvailabilityDays"] as? String ?? ""
    let arr = Array(availableDays)

    let arrAvailability = Array(availability)

    let arr1 = availability.components(separatedBy: ",")

    let value : Int = Int(presentDay) ?? 0
    let day = (value-1)
    let today = "(day)"

    if arr1.contains(today)
    {
    availableToday = true
    }
    else
    {
    availableToday = false
    }

    if valueStatus == "1" && availableToday == true
    {
    let obj = self.storyboard?.instantiateViewController(withIdentifier: "bookingId") as! BookingViewController
    obj.dicBagHanlderDetail = tagValue
    self.navigationController?.pushViewController(obj, animated: true)
    }
    else
    {
    let alert = UIAlertController(title: "Alert!", message: "You can't make booking because store is currently closed.", preferredStyle: .alert)
    let okAction = UIAlertAction(title: "OK", style: .cancel) { (actoin) in
    }
    alert.addAction(okAction)
    self.present(alert, animated: true, completion: nil)
    }

    }





    share|improve this answer




























      0














      Please use below function and resolve an issue. I think it is possible because of the force cast string and int value.



      @objc func pressBookNowButton(button: UIButton) {
      guard let tagValue = self.arrListingBagHandler.object(at: button.tag) else {
      return
      }




      let valueStatus = tagValue["IsOnline"] as? String ?? ""
      let availability = tagValue["AvailabilityDays"] as? String ?? ""
      let arr = Array(availableDays)

      let arrAvailability = Array(availability)

      let arr1 = availability.components(separatedBy: ",")

      let value : Int = Int(presentDay) ?? 0
      let day = (value-1)
      let today = "(day)"

      if arr1.contains(today)
      {
      availableToday = true
      }
      else
      {
      availableToday = false
      }

      if valueStatus == "1" && availableToday == true
      {
      let obj = self.storyboard?.instantiateViewController(withIdentifier: "bookingId") as! BookingViewController
      obj.dicBagHanlderDetail = tagValue
      self.navigationController?.pushViewController(obj, animated: true)
      }
      else
      {
      let alert = UIAlertController(title: "Alert!", message: "You can't make booking because store is currently closed.", preferredStyle: .alert)
      let okAction = UIAlertAction(title: "OK", style: .cancel) { (actoin) in
      }
      alert.addAction(okAction)
      self.present(alert, animated: true, completion: nil)
      }

      }





      share|improve this answer


























        0












        0








        0







        Please use below function and resolve an issue. I think it is possible because of the force cast string and int value.



        @objc func pressBookNowButton(button: UIButton) {
        guard let tagValue = self.arrListingBagHandler.object(at: button.tag) else {
        return
        }




        let valueStatus = tagValue["IsOnline"] as? String ?? ""
        let availability = tagValue["AvailabilityDays"] as? String ?? ""
        let arr = Array(availableDays)

        let arrAvailability = Array(availability)

        let arr1 = availability.components(separatedBy: ",")

        let value : Int = Int(presentDay) ?? 0
        let day = (value-1)
        let today = "(day)"

        if arr1.contains(today)
        {
        availableToday = true
        }
        else
        {
        availableToday = false
        }

        if valueStatus == "1" && availableToday == true
        {
        let obj = self.storyboard?.instantiateViewController(withIdentifier: "bookingId") as! BookingViewController
        obj.dicBagHanlderDetail = tagValue
        self.navigationController?.pushViewController(obj, animated: true)
        }
        else
        {
        let alert = UIAlertController(title: "Alert!", message: "You can't make booking because store is currently closed.", preferredStyle: .alert)
        let okAction = UIAlertAction(title: "OK", style: .cancel) { (actoin) in
        }
        alert.addAction(okAction)
        self.present(alert, animated: true, completion: nil)
        }

        }





        share|improve this answer













        Please use below function and resolve an issue. I think it is possible because of the force cast string and int value.



        @objc func pressBookNowButton(button: UIButton) {
        guard let tagValue = self.arrListingBagHandler.object(at: button.tag) else {
        return
        }




        let valueStatus = tagValue["IsOnline"] as? String ?? ""
        let availability = tagValue["AvailabilityDays"] as? String ?? ""
        let arr = Array(availableDays)

        let arrAvailability = Array(availability)

        let arr1 = availability.components(separatedBy: ",")

        let value : Int = Int(presentDay) ?? 0
        let day = (value-1)
        let today = "(day)"

        if arr1.contains(today)
        {
        availableToday = true
        }
        else
        {
        availableToday = false
        }

        if valueStatus == "1" && availableToday == true
        {
        let obj = self.storyboard?.instantiateViewController(withIdentifier: "bookingId") as! BookingViewController
        obj.dicBagHanlderDetail = tagValue
        self.navigationController?.pushViewController(obj, animated: true)
        }
        else
        {
        let alert = UIAlertController(title: "Alert!", message: "You can't make booking because store is currently closed.", preferredStyle: .alert)
        let okAction = UIAlertAction(title: "OK", style: .cancel) { (actoin) in
        }
        alert.addAction(okAction)
        self.present(alert, animated: true, completion: nil)
        }

        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 3 at 12:04









        Mitul.PatelMitul.Patel

        1126




        1126

























            1














            As others suggested any ! is a potential crash. Try to replace it with guard or default values. For example you can change:



            let valueStatus = tagValue["IsOnline"] as! String
            let availability = tagValue["AvailabilityDays"] as! String


            To solution with default values:



            let valueStatus = tagValue["IsOnline"] as? String ?? "1"
            let availability = tagValue["AvailabilityDays"] as? String ?? "5"


            Or even better guard and e.g. display alert if data aren't available:



            guard let valueStatus = tagValue["IsOnline"] as? String,
            let availability = tagValue["AvailabilityDays"] as? String else {
            // Display alert in case of unavailable data (or simply return)
            let alert = UIAlertController(title: "Alert!", message: "You can't make booking because store is currently closed.", preferredStyle: .alert)
            let okAction = UIAlertAction(title: "OK", style: .cancel) { _ in }
            alert.addAction(okAction)
            self.present(alert, animated: true, completion: nil)
            return
            }
            // Continue as expected here...





            share|improve this answer





















            • 1





              Yeah, thats would work but will lead to wrong behaviour, which makes the user book wrongly. I think the crash happens cause the data return nil, so I think its good if he could debug why this return nil, maybe the way he is passing the tag from the cell.

              – Bassem Qoulta
              Jan 3 at 12:06


















            1














            As others suggested any ! is a potential crash. Try to replace it with guard or default values. For example you can change:



            let valueStatus = tagValue["IsOnline"] as! String
            let availability = tagValue["AvailabilityDays"] as! String


            To solution with default values:



            let valueStatus = tagValue["IsOnline"] as? String ?? "1"
            let availability = tagValue["AvailabilityDays"] as? String ?? "5"


            Or even better guard and e.g. display alert if data aren't available:



            guard let valueStatus = tagValue["IsOnline"] as? String,
            let availability = tagValue["AvailabilityDays"] as? String else {
            // Display alert in case of unavailable data (or simply return)
            let alert = UIAlertController(title: "Alert!", message: "You can't make booking because store is currently closed.", preferredStyle: .alert)
            let okAction = UIAlertAction(title: "OK", style: .cancel) { _ in }
            alert.addAction(okAction)
            self.present(alert, animated: true, completion: nil)
            return
            }
            // Continue as expected here...





            share|improve this answer





















            • 1





              Yeah, thats would work but will lead to wrong behaviour, which makes the user book wrongly. I think the crash happens cause the data return nil, so I think its good if he could debug why this return nil, maybe the way he is passing the tag from the cell.

              – Bassem Qoulta
              Jan 3 at 12:06
















            1












            1








            1







            As others suggested any ! is a potential crash. Try to replace it with guard or default values. For example you can change:



            let valueStatus = tagValue["IsOnline"] as! String
            let availability = tagValue["AvailabilityDays"] as! String


            To solution with default values:



            let valueStatus = tagValue["IsOnline"] as? String ?? "1"
            let availability = tagValue["AvailabilityDays"] as? String ?? "5"


            Or even better guard and e.g. display alert if data aren't available:



            guard let valueStatus = tagValue["IsOnline"] as? String,
            let availability = tagValue["AvailabilityDays"] as? String else {
            // Display alert in case of unavailable data (or simply return)
            let alert = UIAlertController(title: "Alert!", message: "You can't make booking because store is currently closed.", preferredStyle: .alert)
            let okAction = UIAlertAction(title: "OK", style: .cancel) { _ in }
            alert.addAction(okAction)
            self.present(alert, animated: true, completion: nil)
            return
            }
            // Continue as expected here...





            share|improve this answer















            As others suggested any ! is a potential crash. Try to replace it with guard or default values. For example you can change:



            let valueStatus = tagValue["IsOnline"] as! String
            let availability = tagValue["AvailabilityDays"] as! String


            To solution with default values:



            let valueStatus = tagValue["IsOnline"] as? String ?? "1"
            let availability = tagValue["AvailabilityDays"] as? String ?? "5"


            Or even better guard and e.g. display alert if data aren't available:



            guard let valueStatus = tagValue["IsOnline"] as? String,
            let availability = tagValue["AvailabilityDays"] as? String else {
            // Display alert in case of unavailable data (or simply return)
            let alert = UIAlertController(title: "Alert!", message: "You can't make booking because store is currently closed.", preferredStyle: .alert)
            let okAction = UIAlertAction(title: "OK", style: .cancel) { _ in }
            alert.addAction(okAction)
            self.present(alert, animated: true, completion: nil)
            return
            }
            // Continue as expected here...






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jan 3 at 12:26

























            answered Jan 3 at 12:02









            Martin PilchMartin Pilch

            1,66922352




            1,66922352








            • 1





              Yeah, thats would work but will lead to wrong behaviour, which makes the user book wrongly. I think the crash happens cause the data return nil, so I think its good if he could debug why this return nil, maybe the way he is passing the tag from the cell.

              – Bassem Qoulta
              Jan 3 at 12:06
















            • 1





              Yeah, thats would work but will lead to wrong behaviour, which makes the user book wrongly. I think the crash happens cause the data return nil, so I think its good if he could debug why this return nil, maybe the way he is passing the tag from the cell.

              – Bassem Qoulta
              Jan 3 at 12:06










            1




            1





            Yeah, thats would work but will lead to wrong behaviour, which makes the user book wrongly. I think the crash happens cause the data return nil, so I think its good if he could debug why this return nil, maybe the way he is passing the tag from the cell.

            – Bassem Qoulta
            Jan 3 at 12:06







            Yeah, thats would work but will lead to wrong behaviour, which makes the user book wrongly. I think the crash happens cause the data return nil, so I think its good if he could debug why this return nil, maybe the way he is passing the tag from the cell.

            – Bassem Qoulta
            Jan 3 at 12:06




















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54021499%2fapp-crashes-when-button-tapped-with-testflight%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas