0

in a search field if I write in it gives me this error:

Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)

If I type a comma, or a number (so the result is not there) the app works, but if I enter a letter (then find a result) the app crashes.

enter image description here

override func updateControllerViews(_ animated: Bool) {
        super.updateControllerViews(animated)
        
        if textFieldSearch.text == "" {
            containerButtons.isHidden = false
            containerCollectionView.isHidden = true
            imageDeletSearch.image = NSImage.init(named: "menu_header_cerca")
            buttonDeleteSearch.isEnabled = false
        } else {
            containerButtons.isHidden = true
            containerCollectionView.isHidden = false
            imageDeletSearch.image = NSImage.init(named: "searchoff")
            buttonDeleteSearch.isEnabled = true
            
            updateDataSource()
        }
        
        collectionView.reloadData()
    }
func updateDataSource() {
        dataSource = DeviceSearchKeywords.filteredKeywords(byString: textFieldSearch.text)
    }
extension DeviceSearchKeywords {
    static func filteredKeywords(byString string: String?) -> [String : DeviceType] {
        guard let string = string else {
            return [:]
        }
        
        let cleanString = StringUtility.cleaning(string).lowercased()
        
        var filteredKeyword: [String : DeviceType] = [:]
        
        for keyword in mainDeviceKeywords {
            if keyword.lowercased().contains(cleanString) {
                filteredKeyword[keyword] = .deviceMain
            }
        }
    
        for keyword in importDeviceKeywords {
            if keyword.lowercased().contains(cleanString) {
                filteredKeyword[keyword] = .deviceImport
            }
        }
        
        for keyword in exportDeviceKeywords {
            if keyword.lowercased().contains(cleanString) {
                filteredKeyword[keyword] = .deviceExport
            }
        }

        
        return filteredKeyword
    }
}
NcXNaV
  • 1,657
  • 4
  • 14
  • 23
devSwift
  • 1
  • 4

1 Answers1

1

EXC_BAD_INSTRUCTION means that you have an undefined instruction inserted into the code and it's detected at runtime.

You can have either a:

  • Failing a force cast (as!) but there's no evidence in the code you posted
  • Array out of bounds
  • trying to force unwrap (!) a nil optional property

Try do debug your code activating Exception breakpoints if you haven't done it already!

Alastar
  • 1,284
  • 1
  • 8
  • 14
  • what you wrote I already knew, but I don't know how to fix it – devSwift Sep 06 '21 at 14:38
  • yes, View me Thread 4: breakpoint 1.3 and 0x7fff6c7db0f8 <+0>: pushq %rbp – devSwift Sep 06 '21 at 14:50
  • This error doesn't help to solve your issue, you need to post the full code related to this and the line of the error – Alastar Sep 06 '21 at 14:53
  • I published it at the beginning of the post – devSwift Sep 06 '21 at 15:00
  • This is another mistake he gives me: Thread 1: "-[NSNib _initWithNibNamed:bundle:options:] could not load the nibName: NameApp.SearchDeviceCell in bundle (null)." – devSwift Sep 06 '21 at 15:48
  • Do you have a xib named `SearchDeviceCell`? – Larme Sep 07 '21 at 09:46
  • 1
    You should link (inside the Cell Item's .xib) the Item object's view to the root view. And, if you haven't do it, you need to set the nib name needs inside the attribute inspector. – Alastar Sep 07 '21 at 12:21
  • @Alastar I had solved it two days ago, thanks anyway. How did you know this was the problem? I got there by chance. – devSwift Sep 09 '21 at 08:40
  • you mean it was the cell? 'could not load the nibName' was foundamental to solve this – Alastar Sep 09 '21 at 08:55
  • Where did you read it 'could not load the nibName' ? I haven't seen it anywhere. – devSwift Sep 09 '21 at 09:17
  • "This is another mistake he gives me: Thread 1: "-[NSNib _initWithNibNamed:bundle:options:] could not load the nibName: NameApp.SearchDeviceCell in bundle (null)."" you posted this comment 2d ago – Alastar Sep 09 '21 at 09:42
  • No problems. :D – Alastar Sep 09 '21 at 09:59