
Bitesize learning on Swift Development & Apple Ecosystem
Joined August 2021
- Tweets117
- Following502
- Followers160
- Likes20
"Developers can choose a topic and ask questions about technology usage and adoption, refining their designs, resolving issues, and understanding guidelines and tools"
apple.com/newsroom/2021/10/aβ¦
Methods added as extension in the protocol are statically dispatched; a conforming type cannot override methods in an extension. To resolve this, add the method as a requirement of the protocol, while keeping the default implementation in the extension
#Swift
Methods in protocol extension are not part of the requirement of the protocol. They can be used to provide default implementation of the protocol or add "free" functionality to conforming types.
#Swift #SwiftLang
Associate type can be used in protocol to define common interface for multiple object. This allows logic to be reused in different type and prevent duplicate codes.
#Swift
1
When a type conforms to protocol, a protocol witness is passed whenever an instance of that type is constructed. Witness contains the requirement in the protocol that allows operations to be fulfilled (etc == in Equatable ). Explicit Witness can also be created in Struct
#Swift
1
youtube.com/watch?v=3BVkbWXcβ¦
Great explanation on how to use witness-oriented approach in Struct to manage limitation of the protocol oriented way
#iOSDev
1
String in Swift does not conform to MutableCollection; String does not support replacing a character using subscript operator. It does conform to RangeReplaceableCollection; replaceSubrange is needed even when replacing a character in String
#Swift #SwiftLang
1
A String in Swift is a collection of Character values. A single character is what a human reader would perceive, regardless of how many Unicode scalars itβs composed of. Hence, characters have variable width, and String does not support random access.
#Swift
1
Xcode Shortcut: Jump to method/property
When working on large file, press "Control + 6" to display all properties & method in the current file and jump to it base on your selection
#Xcode
Matching cases in Enum
Underscore _ can be used to match any value and ignore it. It is useful to ignore one part of associated value while matching the other.
let can be used to bind part or all the matched value to a new constant to be use in the matched case
#Swift
1
The self parameter implicitly passed into every method of Struct is immutable by default. Set the method as mutating to consider self as a var, so the method can change properties on the Struct instance. Instance of Struct needs to be a var to call the mutating method
#Swift
2
Autoclosure is a closure that wraps an expression thatβs being passed as an argument to a function, so braces can be omitted around a function's parameter. Autoclosure allows delay evaluation, because the code inside isnβt run until the closure is called.
#Swift
Lazy Properties
1. Must always be declared as var since its value may not be set until after initialisation
2. Cannot be defined in an extension
3. Accessing lazy property is a mutating operation, an instance of Struct need to be declare as var to access its lazy property
#Swift
Region Monitoring using CLLocationManager object
Region monitoring send alerts when user enters or exits a defined geographical region. Core Location prevents monitoring of more than 20 regions simultaneously. The regions should be updated when user's location changes.
#iOSDev
Location Monitoring when App is in Background:
Beside getting user's permission for . requestAlwaysAuthorization and checking didUpdateLocations method in CLLocationManagerDelegate, check that Signing & Capabilities > Background Mode > Location updates is turned on
#iOSDev
UIRequiredDeviceCapabilities Property List Key
App Store prevents customers from installing an app on a device that doesnβt support the required capabilities for that app. Use UIRequiredDeviceCapabilities key to declare the capabilities your app requires to function
#iOSDev
SwiftUI's @AppStorage Property Wrapper provide read/write access to user defaults. When the wrapped value change, its view is recomputed base on the new value
#SwiftUI
UISceneDelegate: From iOS13 onwards, scene delegates should be used in place of app delegates for managing what is shown on screen. Etc Preparing UI to run in background/foreground and multi-window support for iPad.
#iOSDev





