Optional Chaining

Optional Chaining Access members of an optional value without unwrapping. Optional chaining is a process for querying and calling properties, methods, and subscripts on an optional that might currently be nil. If the optional contains a value, the property, method, or subscript call succeeds; if the optional is nil, the property, method, or subscript call returns nil. Multiple queries can be chained together, and the entire chain fails gracefully if any link in the chain is nil....

December 1, 2023

Properties

Properties Access stored and computed values that are part of an instance or type. Properties associate values with a particular class, structure, or enumeration. Stored properties store constant and variable values as part of an instance, whereas computed properties calculate (rather than store) a value. Computed properties are provided by classes, structures, and enumerations. Stored properties are provided only by classes and structures. Stored and computed properties are usually associated with instances of a particular type....

December 1, 2023

Protocols

Protocols Define requirements that conforming types must implement. A protocol defines a blueprint of methods, properties, and other requirements that suit a particular task or piece of functionality. The protocol can then be adopted by a class, structure, or enumeration to provide an actual implementation of those requirements. Any type that satisfies the requirements of a protocol is said to conform to that protocol. In addition to specifying requirements that conforming types must implement, you can extend a protocol to implement some of these requirements or to implement additional functionality that conforming types can take advantage of....

December 1, 2023

Strings and Characters

Strings and Characters Store and manipulate text. A string is a series of characters, such as "hello, world" or "albatross". Swift strings are represented by the String type. The contents of a String can be accessed in various ways, including as a collection of Character values. Swift’s String and Character types provide a fast, Unicode-compliant way to work with text in your code. The syntax for string creation and manipulation is lightweight and readable, with a string literal syntax that’s similar to C....

December 1, 2023

Subscripts

Subscripts Access the elements of a collection. Classes, structures, and enumerations can define subscripts, which are shortcuts for accessing the member elements of a collection, list, or sequence. You use subscripts to set and retrieve values by index without needing separate methods for setting and retrieval. For example, you access elements in an Array instance as someArray[index] and elements in a Dictionary instance as someDictionary[key]. You can define multiple subscripts for a single type, and the appropriate subscript overload to use is selected based on the type of index value you pass to the subscript....

December 1, 2023

The Basics

The Basics Work with common kinds of data and write basic syntax. Swift provides many fundamental data types, including Int for integers, Double for floating-point values, Bool for Boolean values, and String for text. Swift also provides powerful versions of the three primary collection types, Array, Set, and Dictionary, as described in doc:CollectionTypes. Swift uses variables to store and refer to values by an identifying name. Swift also makes extensive use of variables whose values can’t be changed....

December 1, 2023

Type Casting

Type Casting Determine a value’s runtime type and give it more specific type information. Type casting is a way to check the type of an instance, or to treat that instance as a different superclass or subclass from somewhere else in its own class hierarchy. Type casting in Swift is implemented with the is and as operators. These two operators provide a simple and expressive way to check the type of a value or cast a value to a different type....

December 1, 2023

Learning/Swift

Swift API Design guidelines Swift.org - API Design Guidelines #weblinks https://www.swift.org/documentation/api-design-guidelines/ layout: page title: API Design Guidelines official_url: https://swift.org/documentation/api-design-guidelines/ redirect_from: /documentation/api-design-guidelines.html {% capture expand %}{::nomarkdown} {:/nomarkdown}{% endcapture %} {% assign detail = ‘’ %} {% assign enddetail = ‘’ %} Table of Contents {:.no_toc} TOC {:toc} Fundamentals Clarity at the point of use is your most important goal. Entities such as methods and properties are declared only once but used repeatedly....

January 24, 2023

learning/swift-dsa

DSA If the input array is sorted then: use Binary search or Two pointers patterns/technique. If asked for all permutations or subsets then use the Backtracking technique. If given a tree then use DFS or BFS. If given a graph then use DFS or BFS. If given a linked list then use the Two Pointers technique with probably the Fast/Slot Pointers technique. If recursion is banned then use a Stack. If must solve in-place then you can Swap corresponding values or Store one or more different values in the same pointer....

January 23, 2023

Learning/Architecture

iOS Architecture Analytics Architecture MVVM The MVVM (Model-View-ViewModel) architecture is a design pattern that is used to structure the code in iOS apps. It is similar to the MVC (Model-View-Controller) architecture, but it introduces a new component called the ViewModel. The ViewModel is responsible for exposing data to the View and facilitating communication between the Model and the View. One of the main benefits of using MVVM is that it helps to separate the business logic of an app from the user interface, which makes it easier to develop and maintain the app over time....

January 22, 2023