Is it acceptable to create multiple classes in one .swift file, or should I create a separate .swift file for each class?

前端 未结 3 1406
臣服心动
臣服心动 2021-01-17 07:34

Is it considered poor technique to create multiple classes in one swift file, or is it best to create a separate swift file for each class?

3条回答
  •  醉酒成梦
    2021-01-17 08:04

    It's not a poor technique, IF the classes are connected.

    To decide if they are connected, ask: Can one class be used without the other?

    If yes, then you should have two different files, since you might need to use just one of the two.


    For example, in C++, collections have an inner class for their iterators. (I know it's a C++ example, but the question isn't really language related).

    Though if the classes have nothing to do with each other (being on the same view doesn't count), then they should each have their separate classes.

提交回复
热议问题