Refactor broke everything


Adding this in case anyone else has had similar issues…

Following the instructions in the 8th edition of iOS Apprentice, chapter 11, page 364, I used “refactor” to rename the ContentView to ChecklistView.

For some reason, that went terribly wrong, and nothing worked for a while. I then had to manually rename the ContentView.swift file in the finder, and then had to go through the code and manually rename instances of “contentView” or “ContentView” with “checklistView” or “ChecklistView.”

After renaming things manually, all seems to be working. But I wonder if the refactor tool in XCode doesn’t really work as expected.

I went thru that chapter today and did the same refactoring thing… Other than it not renaming the comment one (Which was noted in the book), everything worked fine for me…

1 Like

Hey, @oaklazza!

I know that @jamesh has already tried the refactor exercise and it worked, but I’ll do it later today and see if I ran into the same problem you did.

1 Like

Hey, @oaklazza!

I have it a try and didn’t encounter any of the problems you had with refactoring. I’ll give it another try this weekend on a different machine, just in case there’s something unusual with the setup on my primary development Mac.

1 Like

Thanks @accordionguy and @jamesh.

I’m up to the second refactor task, and I think I see where my Xcode environment is behaving differently than what’s shown in the book…

When I do a refactor, it only seems to show results for the current file, even though “All” is selected. (And “All” in my view is “4,” rather than the “7” in the example.)

Here’s what I see when I do refactor:


As opposed to the book, which shows that refactor should be searching across all files:


Any ideas why I might be seeing a different behavior? It’s as if refactor isn’t “aware” of the other files.

And thanks!

Same thing happen to me today. I refactor the ContentView.swift file and the file icon become blurred out. When I clicked on file the system sound (sound when something is unavailable) heard and file content didn’t show up in editor.

Then I renamed(in Xcode) ChecklistView.swift file manually back to ContentView.swift and everything worked. But when I try to renamed ContentView.swift file manually back to ChecklistView.swift I got an error that said: This file cannot be renamed from “ContentView.swift” to “ChecklistView.swift” or something similar.

I quit Xcode and opened it again, then trying to rename ContentView.swift file back to ChecklistView.swift file and everything worked as aspected. I can’t reproduce this bug so I can’t really give the exact error.

Hope to help someone with same issue.

@oaklazza Do you still have issues with this?

I ran into the same problem- refactoring broke my app. However, the fix was fairly simple-- Finder showed that my ContentView.swift file in the app folder had not been renamed. By Control-clicking on that file in Finder, I was able to rename the file to ChecklistView.swift and everything seems to be working.

This topic was automatically closed after 166 days. New replies are no longer allowed.