0

I've already searched a lot but any answer fixed the problem. I've created an app group, selected it on both app and today extension, they're linked to the same group now. I'm trying to load data from the app and display it on a table view on the today extension, the thing is that I'm getting a crash saying that my array is nil, and it cannot be nil. I don't know why tho, cause I'm putting the data into the array. Here is my code:

func handleData() {
    let defaults = NSUserDefaults(suiteName: "MY APP GROUP HERE")

    if let descriptionsArr = defaults?.valueForKey("descriptions") as? [String] {
        descriptions = descriptionsArr
    }


    defaults?.synchronize()
}

So, I'm pretty sure the app group is spelled right, and the value key. What could it be that is making my array nil? Really need help!

Thanks.

Henrique Dourado
  • 320
  • 1
  • 7
  • 16
  • On which line does the crash occur? – Michael Mar 15 '16 at 00:20
  • When I set the descriptions array to the saved array – Henrique Dourado Mar 15 '16 at 00:27
  • Are you saying the line `descriptions = descriptionsArr` is actually crashing because `descriptionsArr` is nil? This should not be possible because it's inside an `if let`. Are you sure it's not the fact that the `if let` fails and therefore `descriptions` is not set, and code elsewhere then fails because it's expected to have a value? – Michael Mar 15 '16 at 00:35
  • Hmm, I actually have no idea. It's saying that some NSArray is nil and it cannot be nil, I'm not sure of why its happening! – Henrique Dourado Mar 15 '16 at 00:40
  • It's probably somewhere else - put a break on all exceptions and it will show you the line of code failing. – Michael Mar 15 '16 at 00:41
  • Check this answer it's for keyboard extension might be help you. http://stackoverflow.com/questions/35411165/how-to-add-custom-notification-in-ios-custom-keyboard/35428839#comment58558395_35428839 – kb920 Mar 15 '16 at 04:13

0 Answers0