[Solved] If condition issues in swift


You need to check whether an array has an element or not.

if addonCategory.count > 0 {
    // array has element
} else {
   // array hasn't element
}

Alternatively you can use guard let or if let to check.

Using if let

if let addonCategory = subCategoryModel[tappedIndex.section].items[tappedIndex.row].addonCategory, addonCategory.isEmpty {
    print(addonCategory)

    print("Hello")
} else {
    print("Hi")
}

11

solved If condition issues in swift