If I keep my extension and private Types very confined inside one single Swift file because I will only ever need it inside that one file, will it improve compiler time and/or performance? Or is the Swift compiler so intelligent and doesn't matter at all?
Example: One iOS Xcode project with over 600 Swift files (moderately huge project) with an already existing network class:
NetworkController.swift
class NetworkController {
let queue = OperationQueue()
func add(_ op: Operation) {
queue.addOperation(op)
}
}
Now I need to add a new class which only does a legacy operation. Which means that all the other components in the iOS app will never ever need it.
LegacyController.swift (everything put into same file)
internal final class LegacyController {
let network = NetworkController()
func start() {
network.requestSomeLegacyStuff {
print("blub")
}
// do lots of other work here ...
}
}
extension NetworkController {
fileprivate func requestSomeLegacyStuff(success: () -> Void) {
let operation = RequestLegacyDataOperation()
add(operation)
}
}
fileprivate final class RequestLegacyDataOperation: Operation {
// do lots of work here ...
}
VERSUS put them into their own files for better visibility and separation, but would then need to change to internal
scope, which is not needed at all.
LegacyController.swift
internal final class LegacyController {
let network = NetworkController()
func start() {
network.requestSomeLegacyStuff {
print("blub")
}
// do lots of other work here ...
}
}
NetworkController+LegacyStuff.swift
extension NetworkController {
internal func requestSomeLegacyStuff(success: () -> Void) {
let operation = RequestLegacyDataOperation()
add(operation)
}
}
RequestLegacyDataOperation.swift
internal final class RequestLegacyDataOperation: Operation {
// do lots of work here ...
}