Separation of function declaration and definition in Swift

后端 未结 5 2109
遥遥无期
遥遥无期 2021-01-06 06:00

I\'m having a look at the new Swift. I come from C, C++, Objective-C... I notice that in swift is not possible (?) to separate the declaration and the definition of function

5条回答
  •  清歌不尽
    2021-01-06 06:41

    Swift doesn't let you separate declarations from implementations. This cuts both ways -- on the one hand, you can't (manually) write a header file that describes the interface you want to expose for users of your code. On the other, you don't have to manually keep your header files up to date and in sync with your implementations.

    Instead, Swift has an access control mechanism. Use the public, internal (implied), and private keywords to mark which types and functions you intend to expose.

提交回复
热议问题