-
Using Containers
-
StackViews
- View embeded with other views
-
Mutating Methods within Struct
- Enable changes to the variable within the Struct when invoking
- "The problem is that when you create the struct Swift has no idea whether you will use it with constants or variables, so by default it takes the safe approach: Swift won’t let you write methods that change properties unless you specifically request it." ~ HackingWithSwift
-
Setting current Button Title via code:
button.setTitle("my text here", forState: .normal)
-
Rounding off a Float or other value:
print(String(format: "%.2f", sender.value))
-
- Structs are passed around by Value
- Classes are passed around by Reference
- Structs are immutable
- Classes have ingeritance
- Ref Reading: [https://docs.swift.org/swift-book/LanguageGuide/ClassesAndStructures.html]
-
CGRect
: Core Graphics Rectangle -
Adding to View by code/ Programatically:
// Inside viewDidLoad()
view.backgroundColor = .red
let label = UILabel()
label.text = "Hello Second View controller"
label.frame = CGRect(x: 0, y: 0, width: 100, height: 50)
view.addSubview(label)
-
Downcasting
let destinationVC = segue.destination as! ResultViewController
-
String
let str = String(format: "%.2f", 1.2334)
RESULT: 1.23
-
UIViewController Nagivation:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "MySegueId" {
if let nextViewController = segue.destination as? NextViewController {
nextViewController.valueOfxyz = "XYZ" //Or pass any values
nextViewController.valueOf123 = 123
}
}
}
- Scalar Images vs Vector Images
-
Dismiss the keyboard:
searchTextField.endEditing(true)
-
Type Alias:
- Example: Codable is a type alias for the Encodable and Decodable protocols. When you use Codable as a type or a generic constraint, it matches any type that conforms to both protocols.
- Defining Extension
extension SomeType {
// Add new functionality
// It could extention to a class, struct, protocol
}
-
Create sections in the file:
//MARK: - {Secion Name}
-
Localized is referenced to local language that the user has selected. Eg. localizedDescription is a description which will be displayed in user's local device language which has been set by the user.
-
[weak self]
Understanding weak self in programming, especially in the context of Swift, involves a few concepts related to memory management. let's deep dive
- Besher Al Maleh on [weak self]
- Quora: what does [weak self] mean in a closure?
- weak self and unowned self explained by Antoine Van Der Lee
-
There will only ever be one copy of these properties, no matter how many instances of that type you create. These kinds of properties are called type properties.
-
is
is used for Type Checking -
as!
is used for Forced Downcast -
as?
is used for Safe Downcast -
as
is used for Upcasting. From subclass to superclass. -
Local Data Persistance using User Defaults, Core Data and Realm
-
Ternary Operator
value = condition ? valueIfTrue : valueIfFalse`
Example:
cell.accessoryType = item.done == true ? .checkmark : .none
- Concurrency and Asynchronous Programming:
- Swift Concurrency: With the introduction of async/await in Swift 5.5, handling asynchronous tasks has become more straightforward.
- Combine: Apple's framework for handling asynchronous events with a declarative approach, which can be beneficial in networking scenarios
- An object that manages the execution of tasks serially or concurrently on your app's main thread or on a background thread.
- More on DispatchQueue
Snippet of Info:
1. IBOutlet - Interface Builder Outlet
2. Who.What = Value
3. IBOutlet = Actions are from Code to Design
4. IBAction = Actions are from Design to Code
5. Random Number = **Int.random(in: 0...5)**
6. Random Element in an ``` Array = arrayVar.randomElement()
7. func myFunction(parameter: DataType) { ... }