Big Swift class leads to slow autocomplete inside Xcode - how to split into multiple files

My Swift Xcode project has a subclass as the main class NSViewController(after that the “main controller”), which grew by about 4 thousand lines. Most of the logic associated with the main window and the main actions of the application is inside this file as class methods.

This makes Xcode very slow when it comes to autocomplete and typing in general. I want to split the logic into several small files, which I hope will speed up my workflow. How can i do this?

If I should be more specific, I would suggest what I want to achieve: move the methods from this main controller to a separate file / class, and then call from the main controller any of these methods that I moved (ideally, this function is in a separate file could call other methods inside the main controller).

Is there anything extensionthat could help in this matter?

thanks

+4
source share
2 answers

You essentially answered your question with an extension that does not require the use of inheritance or subclasses.

With the help of extensionyou can move the code to other files and still get access to everything, this is your original ViewControllerclass, as if it were in one file.

:

class viewController : NSViewController {


}

// new file
extension viewController {

}
+5

, .

, , .

+1

Source: https://habr.com/ru/post/1619929/


All Articles