beeb
beeb

Reputation: 1217

Big Swift class results in slow autocomplete inside Xcode - How to split into several files

My Swift Xcode project has as main class a NSViewController subclass (thereafter the "main controller") which grew to be about 4k lines tall. Most of the logic tied to the main window and main actions of the app are inside this file, as methods of the class.

This results in Xcode being super slow when it comes to autocompletion and typing in general. I want to split the logic into several smaller files which will hopefully speed up my workflow. How can I proceed to do this?

If I have to be more specific, I would guess that what I want to achieve is: moving 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 in a separate file would be able to call other methods inside the main controller as well).

Are extensions something that could help in this matter?

Thanks

Upvotes: 4

Views: 642

Answers (2)

chiarotto.alessandro
chiarotto.alessandro

Reputation: 1589

I would make a new controller class and I would set it as a parent of your controller.

In this way you can move your methods to the new the parent controller without changing the logic of you app.

Upvotes: 1

Ollie
Ollie

Reputation: 1946

You've essentially answered your own question with the extension's that don't require the use of inheritance or subclasses.

With extensions you can move code to other files and still access everything is your original ViewController class as if it was within the same file.

Example:

class viewController : NSViewController {


}

// new file
extension viewController {

}

Upvotes: 5

Related Questions