-
(Swift) Structures VS. ClassesiOS💖 2024. 9. 3. 17:58
Choose Structures by Default!
- Use structures by default.
- Use classes when you need Objective-C interoperability.
- Use classes when you need to control the identity of the data you’re modeling.
- Use structures along with protocols to adopt behavior by sharing implementations.
>> 2, 3번은 줄어드는 추세이고, 실무시에는 1, 4번의 경우가 많다고 한다.
< 실무 추세 >
- structures 를 기본으로 사용하고 (data modeling)
- 최대한 상속을 안쓰는 추세 (final class)
- structures/classes 에서 행동에 대한 채택이 필요한 경우;
protocol을 이용
>> structures / classes 모두에서 행동을 채택할 수 있기에
참고)
https://developer.apple.com/documentation/swift/choosing-between-structures-and-classes
Choosing Between Structures and Classes | Apple Developer Documentation
Decide how to store data and model behavior.
developer.apple.com
'iOS💖' 카테고리의 다른 글
(iOS) Life Cycle (AppDelegate / SceneDelegate) (4) 2024.09.06 (Swift) POP (Protocol Oriented Programming) (0) 2024.09.04 (Swift) deinitializer (3) 2024.09.03 (Swift) Access Control (2) 2024.09.03 (Swift) Type Properties & Methods (0) 2024.09.03