|
Hi Everyone, I'm coming to you hat-in-hand again, as I'm really struggling with a point of my app that keeps crashing when I go to click on a cell in my list. Namely I get this error: Thread 1: "-[AccountBackEnd accountCompanyName]: unrecognized selector sent to instance 0x6000025aac40.". This appears right on the line of @main in the file that renders the app's output. To make matters worse, this is in SwiftUI and there doesn't seem to be a lot of documentation on this error online. I'm not 100% sure, but I think it's got something to do with a syste for navigation that I downloaded, I was using which was meant to make navigation simpler. I don't think that's the case here. I've begun the process of going away from that system of buttons to use the more conventional NavigationView and NavigationLink. I've managed to deal with a few errors already here, but this one seems to be kicking my butt pretty badly. I'm at a loss. I'll put my code below for your review. As always, any help here is greatly, greatly appreciated. Database view, this contains the app's list
AccountDetailMain, this presents the user with their Account's info. I believe this is the part that is actually crashing the app?
AddAccountView, I can get this to load without challenge, where again it seems to be the AccountViewMain view that has issues.
...As well, here's the last page with @main that has the issue on it:
|
|
I don't see a definition of your AccountBackEnd class. But I was first struck by the question "Why are you identifying your objects in a ForEach loop with .self?
You want unique items in your List, so when you send them to a new view, SwiftUI knows exactly what row is being rendered, updated, or deleted. Another thought: You're looping through a found set names accounts. Your loop variable is named account. You use account.accountCompanyName as the filler for your navigation link's label. Yet, you're passing an accountBackEnd over to your AccountDetailMain() view. Since you are tapping a single account row, isn't this what you want to pass to your detail view? Another thought: You've provided lots o' code! Much of this isn't pertinent to the problem. Have you tried commenting out big chunks of code to focus your attention on the source of the issue? I'm not ready to do a deep dive into this code, but some of the code looks like red herring stuff. Is it a problem? Or just a decoy? For example, in your last code snip, I am not sure why you defined the account var ? This var is local to RangerCRM. But I do not see it used in a view, nor do I see it being passed to your StatsAndDataTabView. Is this an issue? part of the problem? and oversight? It's a distraction.
|
|
Hi @Obelix, Thanks you for taking the time to respond. As I'm sure you can tell, I'm learning while building. Thankfully I'm not building a house. I'll try to answer your questions in sequence and see if that helps to clarify things. 1) My AccountBackEnd class is from Core data. So the actual class looks pretty empty. I'm honestly too green to tell if that's normal or not?
2) Re my naming conventions, I thought it made more sense to keep my properties with lower case and the structs/classes with upper case. Admittedly I'm unsure how else to call the data from the list cell to the AccountViewMain in a way that makes sense. 3) Greying out code: This is one thing I've been doing, and has actually helped to really clean up parts of my code I don't need. I will continue to work on this. 4) Really good point. I greyed that one out, and have since removed it. For what it's worth, I really do appreciate your time here. There's no one in my life that can go over this stuff with me so it really does help. Thank you! |
|
Does your Also:
I don't quite understand this line. If an |
|
Hi @roosterboy! Thanks for your reply! I just checked the AccountBackEnd, and there is a property there for accountCompanyName. This is found in its extension though. There is nothing in the class. I'll put the call below below.
As for your second part, I thnk this is where I'm getting the most confused. From what I know, the way to initialize something is like, init() {}. Is that correct? Is there a different way to initialize a class though? Initializing is something I'm still trying to get my head around beforte I go too further here. Thanks! EDIT To be clear there's wayyy more going on in an init() call, but I was trying to give the rough idea. Cheers! |
|
A little trick to find out which line of code is causing the exception:
Xcode shows you the line of code that's causing the issue. |
|
You have this in several of your
What type is |
BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.