Why do we need separate “.swift” files for each class?

后端 未结 6 1225
刺人心
刺人心 2020-12-29 05:02

Wondering if you might be able to answer a very basic beginner question for me. I’m working through the Cocoa + Swift tutorial on Lynda and I’m a little confused about class

6条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-29 05:43

    I just want to add the observation that Swift's fileprivate access modifier actually sometimes requires putting many classes inside a single source file. The "one class per source file" doesn't necessarily fit the design of Swift. For this reason, when I need to tightly control which properties I expose, I often have one very large source file for a single API.

    The only alternative is to make a separate framework for each API and using internal fields.

提交回复
热议问题