Automatic reference counting
shape
NSNotificationCenter
is a powerful mechanism that allows objects to communicate with each other in a loose coupling way. It is used to broadcast messages (notifications) to interested objects without the need for them to be directly linked. This is especially useful for event-driven programming and for objects that need to respond to changes or specific events in other parts of the application. @selector
is a compiler directive used to represent a selector, which is a type that refers to the name of a method. A selector is essentially a way to refer to a method by its name so that it can be called dynamically during runtime. It is frequently used in contexts like message sending, target-action patterns, and performing selectors. @property
is a directive used to declare a property on an object, which is a getter and setter method for an instance variable (ivariable). It allows the automatic creation of accessors (getter and setter methods) and provides encapsulation and memory management for the instance variables, ensuring a clean and simple interface to interact with an object's data. @synthesize
is a directive used to automatically generate the getter and setter methods for a property, as well as the instance variable (ivar) associated with that property. However, with the introduction of Automatic Reference Counting (ARC) and modern Objective-C, @synthesize
has become less necessary in most cases, as the compiler now automatically synthesizes properties for you by default. But understanding its historical usage and functionality is still important. async
and await
are keywords introduced in Swift 5.5 to simplify writing asynchronous code. These keywords help manage concurrency and make asynchronous programming more readable and less error-prone compared to traditional callback-based methods like closures. @IBOutlet
and @IBAction
are attributes used in iOS development with UIKit (or SwiftUI in some cases, although the syntax differs). These attributes are used to connect UI elements in Interface Builder (the visual tool within Xcode) to your Swift code, enabling interaction between your user interface (UI) and the logic of your application. struct
) are used to create custom data types, but they differ in several key aspects, primarily in how they manage memory, behavior, and mutability. Understanding these differences is crucial for choosing the right type for your application. map
, filter
, and reduce
are powerful higher-order functions that operate on collections (such as arrays, sets, etc.) and allow you to transform, filter, or combine values in a concise and functional programming style. These functions are commonly used to manipulate data in a functional programming way. defer
is a powerful control flow statement that allows you to execute a block of code just before the current scope exits, no matter how the scope is exited (whether through normal return, early exit due to an error, or other control flow mechanisms). The purpose of defer
is to ensure cleanup code is always executed, even in the face of errors or early exits from functions. let
and var
are both used to declare variables, but they differ in terms of mutability:- let
: This keyword is used to declare constants, meaning the value assigned to the variable cannot be changed after it is set. Once a value is assigned to a let
constant, you cannot modify it. This is similar to declaring an immutable reference.