Swift Interview Questions and Answers
Ques 1. What is the purpose of the 'NSCoding' protocol in Swift?
The 'NSCoding' protocol is used for encoding and decoding objects, typically for archiving and unarchiving data in iOS and macOS apps.
Ques 2. Explain the concept of key paths in Swift.
Key paths provide a way to reference properties in a type-safe manner. They are used in KVO, functional programming, and the 'Codable' protocol.
Ques 3. How does Swift handle memory leaks, and what are some common causes?
Swift uses Automatic Reference Counting (ARC) to manage memory, but memory leaks can still occur if strong reference cycles are created. Common causes include strong reference cycles between objects.
Ques 4. What are Swift access control levels, and how are they used?
Swift has five access control levels: 'open', 'public', 'internal', 'fileprivate', and 'private'. They control the visibility of classes, methods, and properties.
Ques 5. What is Swift?
Swift is a programming language developed by Apple for iOS, macOS, watchOS, tvOS, and Linux applications.
Most helpful rated by users:
- What is Swift?
- Explain optionals in Swift.
- What is the difference between 'let' and 'var' in Swift?
- What are property observers in Swift?
- What is the purpose of the 'static' keyword in Swift?