Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Introduction to Table Views Displaying Contact Data Working With Reusable Cells

Emre Havan
Emre Havan
8,569 Points

Problem with PListLoader code snippet, related: Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)

So I was following the steps on the video, I have also copied and pasted the code snippet provided from the instructor, so according to code, the reason Im getting this error seems to be that kind of a file does not exist.

But I do have that DB.plist file in the same folder, as the instructor has, I just could not figure out why mine did not workout.

class ContactsSource {
    static var contacts: [Contact] {
        let data = try! PlistLoader.array(fromFile: "ContactsDB", ofType: "plist")
        return data.flatMap { Contact(dictionary: $0) }
    }

}

I get the thread on the line: let data = try! PlistLoader.array(fromFile: "ContactsDB", ofType: "plist")

Thanks in advance

3 Answers

Jaroslaw Adamowicz
Jaroslaw Adamowicz
11,634 Points

Hi,

what you have here is error durring execution of your program. This may happen if for example you try to open file that doesn't exists!

What I can read from your post is:

But I do have that DB.plist file in the same folder, as the instructor has, I just could not figure out why mine did not workout.

I think I was even able to reproduce your error, please check image below:

bad_exec

Please notice: I'm using file named DB.plist instead of ContactsDB.plist !

So my question is: What is name of your plist file? Is it

DB.plist

or maybe

ContactsDB.plist

?

Because in this line:

        let data = try! PlistLoader.array(fromFile: "ContactsDB", ofType: "plist")

in parameter called fromFile if you put any string it will compile, but if there is no file named as that string it will give you error durring execution.

So you need either to change parameter in line above to match your filename, like this:

        let data = try! PlistLoader.array(fromFile: "DB", ofType: "plist")

or change filename back to "ContactsDB.plist"

Cheers!

BR, Jarek

Emre Havan
Emre Havan
8,569 Points

Hey there!

Thank you so much for your reply, my file name was indeed "ContactsDB.plist" as it is correctly written in the code as well.

I could not figure out why and then I just deleted the file, re-downloaded and changed the name before I copy in to the folder, and also updated the code with the new name.

Now it works, but seriously I still dont know what was the problem in the first place :D

But thanks a lot for help and suggestions!!

Jaroslaw Adamowicz
Jaroslaw Adamowicz
11,634 Points

Hi, maybe your file was corrupted?

Most importantly you solved it and can move forward! Congrats!

BR, Jarek

Ian Billings
PLUS
Ian Billings
Courses Plus Student 7,494 Points

Hi,

I just wanted to add I had this same problem and it was because, in Xcode when I imported the file, it hadn't added it properly. To fix it, I clicked the ContactsDB.plist file and then in the inspector on the right hand side, under 'Target Membership' make sure the project name was selected. I wonder if this is a bug with the latest version of Xcode.

Regards

Ian

Jaroslaw Adamowicz
Jaroslaw Adamowicz
11,634 Points

Hi Ian, it is very possible and I think you're totally right!

I'm playing around with SpriteKit now and very similar issue happens to me when adding folders with .atlas extension to create so called texture atlases. When I run the program it simply cannot find damn files and aftere several hours I found this checkbox unchecked in File Inspectore for Target Membership. After checking in files were found and everything worked as expected!

I guess some new XCode bugs were introduced :)

Now when I add new atlas I've always check this box and have no issues since then.

BR, Jarek