Tsallaka zuwa abun ciki
Justice Tech School

Swift Tutorial

Apple's language for iOS, macOS and beyond.

Start learning Swift
Getting started3 lessons
  1. 1Swift IntroductionSwift is Apple's modern language for iPhone, iPad, Mac, Apple Watch and Apple TV apps.
  2. 2Swift Get StartedInstall Xcode on a Mac or the Swift toolchain on Linux and Windows.
  3. 3Swift SyntaxSemicolons are optional.
Basics26 lessons
  1. 4Swift Variables and Constantslet creates a constant and var a variable.
  2. 5Swift Data TypesCommon types: Int, Double, Float, Bool, String and Character.
  3. 6Swift StringsStrings use \(value) interpolation.
  4. 7Swift OptionalsAn optional may hold a value or nil, written with ?.
  5. 8Swift Type ConversionConvert with initialisers: Int("42") returns an optional, String(42) always works.
  6. 9Swift TuplesA tuple groups several values, possibly of different types, and can name its parts.
  7. 10Swift BooleansBool is true or false.
  8. 11Type Safety and AliasesSwift is type safe: a variable keeps its type.
  9. 12Swift CommentsUse // for one line and /* */ for several lines.
  10. 13Swift Numbers and MathInt and Double support the usual math.
  11. 14let and varlet makes a constant and var a variable.
  12. 15Basic TypesInt, Double, Float, Bool, String and Character.
  13. 16OptionalsAn optional holds a value or nil.
  14. 17String Interpolation\(expression) inserts values.
  15. 18TuplesA tuple groups values.
  16. 19OperatorsArithmetic, comparison, logical, range and nil coalescing operators.
  17. 20Type Castingas? safely casts, as! forces and is tests a type.
  18. 21Math and RandomFoundation has sqrt, pow, abs, floor.
  19. 22Reading InputreadLine() returns an optional String from standard input.
  20. 23Type Aliases and Constantstypealias gives a type a new name.
  21. 24print Optionsprint takes separator and terminator.
  22. 25Comments// is a line comment and /* */ a block that can nest.
  23. 26Number Literals and OverflowUse underscores, binary, hex and octal literals.
  24. 27Identity and Equality== compares values and === compares class instance identity.
  25. 28Optional Binding PatternsCombine if let, guard let and multiple bindings.
  26. 29assert and preconditionassert checks during development only.
Operators2 lessons
  1. 30Swift OperatorsArithmetic: + - * / %.
  2. 31Swift Ranges1...3 includes 3 and 1..<3 stops before it.
Control flow11 lessons
  1. 32Swift If and ElseConditions need no parentheses but braces are required.
  2. 33Swift Switchswitch must cover every case and there is no implicit fallthrough.
  3. 34Swift Loopsfor in loops over ranges and collections.
  4. 35Swift Guardguard checks a condition and exits early if it fails, keeping the main path flat.
  5. 36if and elseConditions need no parentheses and braces are required.
  6. 37switchswitch must be exhaustive and does not fall through.
  7. 38for in Loopsfor in walks ranges, arrays, dictionaries and strings.
  8. 39while and repeatwhile checks first and repeat while runs at least once.
  9. 40guardguard exits early when a condition fails.
  10. 41break, continue and Labelsbreak leaves a loop, continue skips a round and labels target outer loops.
  11. 42Rangesa...b is closed and a..<b is half open.
Collections14 lessons
  1. 43Swift ArraysAn array is an ordered list of one type.
  2. 44Swift DictionariesA dictionary maps unique keys to values.
  3. 45map, filter and reduceCollections support functional operations: map transforms, filter keeps matches, reduce co.
  4. 46Swift SetsA Set stores unique, unordered values with fast lookup.
  5. 47Sorting and Searchingsorted returns a new array and sort() sorts in place.
  6. 48ArraysArrays are ordered and typed.
  7. 49Array Operationsmap, filter, reduce, sorted, contains, firstIndex and joined are common.
  8. 50SetsSet stores unique values with fast membership.
  9. 51DictionariesA dictionary maps keys to values.
  10. 52Slices and RangesA slice is a view of part of an array.
  11. 53Grouping and ZippingDictionary(grouping:by:) buckets items.
  12. 54compactMap and flatMapcompactMap drops nils and flatMap flattens nested arrays.
  13. 55StringsStrings are Unicode aware.
  14. 56String IndexingUse String.Index with startIndex, index(_:offsetBy:) or convert to an Array.
Functions10 lessons
  1. 57Swift FunctionsDeclare with func.
  2. 58Swift ClosuresA closure is a function without a name in braces: { params in body }.
  3. 59Variadic and inout ParametersA variadic parameter accepts many values.
  4. 60Functionsfunc declares a function with typed parameters and a return type.
  5. 61Default and Variadic ParametersGive defaults and use .
  6. 62inout Parametersinout lets a function change the caller variable.
  7. 63ClosuresA closure is { params in body }.
  8. 64Functions as ValuesFunctions are values.
  9. 65RecursionA function may call itself with a base case.
  10. 66Nested Functions and ScopeFunctions can live inside functions and capture local variables.
Object oriented Swift20 lessons
  1. 67Swift StructsA struct is a value type with properties and methods and a free memberwise initialiser.
  2. 68Swift ClassesA class is a reference type that supports inheritance.
  3. 69Swift PropertiesStored properties hold values, computed properties calculate them with get and set, and pr.
  4. 70Swift InheritanceA class can inherit from one superclass.
  5. 71Swift ProtocolsA protocol lists requirements a type must meet, like an interface.
  6. 72Swift ExtensionsAn extension adds methods, computed properties and protocol conformance to an existing typ.
  7. 73Swift EnumsAn enum defines a group of related values.
  8. 74Access ControlKeywords private, fileprivate, internal (default), public and open control who can use a m.
  9. 75StructsStructs are value types.
  10. 76ClassesClasses are reference types with inheritance.
  11. 77PropertiesStored properties hold values.
  12. 78Methods and mutatingMethods on structs that change the instance must be marked mutating.
  13. 79InheritanceA class inherits with a colon.
  14. 80ProtocolsA protocol lists requirements.
  15. 81ExtensionsExtensions add methods and computed properties to existing types.
  16. 82EnumsEnums define a set of cases that can carry values and methods.
  17. 83GenericsGenerics write code for any type with constraints.
  18. 84Optional Chaininga?.b?.c stops at the first nil and returns nil.
  19. 85Access Controlopen, public, internal, fileprivate and private control visibility.
  20. 86InitialisersDesignated initialisers set every property.
Errors and memory13 lessons
  1. 87Swift Error HandlingErrors are types that conform to Error.
  2. 88Memory and ARCSwift manages class memory with automatic reference counting.
  3. 89Errors with throw and do catchFunctions that throw are marked throws and called with try.
  4. 90try? and try!try? turns errors into nil and try! crashes on error.
  5. 91deferdefer runs code when the scope ends, great for cleanup.
  6. 92Memory and ARCSwift counts references to class instances.
  7. 93Result TypeResult<Success, Failure> carries a value or an error.
  8. 94Codable and JSONCodable converts types to and from JSON with JSONEncoder and JSONDecoder.
  9. 95Dates and FilesDate, DateFormatter and FileManager handle dates and files.
  10. 96async and awaitasync functions suspend and await waits for them.
  11. 97Practice: Word FrequencySplit, group and sort.
  12. 98Practice: FizzBuzzCombine a range with switch on a tuple.
  13. 99Practice: Bank AccountCombine struct, mutating and errors.
Advanced SwiftPremium5 lessons
  1. 100Swift GenericsGenerics let functions and types work with any type while staying safe.
  2. 101Swift Concurrencyasync functions can suspend and await waits for results without blocking threads.
  3. 102Property Wrappers and Result BuildersA property wrapper adds reusable behaviour to properties, such as @State in SwiftUI.
  4. 103Opaque Types and somesome Protocol returns a specific type without naming it.
  5. 104Codable and JSONConform to Codable to convert types to and from JSON with JSONEncoder and JSONDecoder.
Swift in practicePremium9 lessons
  1. 105SwiftUI BasicsSwiftUI builds interfaces with simple declarative code.
  2. 106SwiftUI State and Binding@State stores local view data and changes redraw the view.
  3. 107SwiftUI Lists and NavigationList shows rows, ForEach builds repeated views and NavigationStack moves between screens w.
  4. 108Networking with URLSessionURLSession downloads data.
  5. 109Saving DataUserDefaults stores small settings, FileManager works with files, and SwiftData or Core Da.
  6. 110Testing SwiftXCTest and Swift Testing check your code.
  7. 111Swift Package ManagerSwiftPM manages dependencies and builds.
  8. 112Publishing to the App StoreYou need an Apple Developer account, a signed build, app icons, screenshots and a privacy .
  9. 113Swift Best PracticesPrefer let and structs, use optionals instead of sentinel values, name functions by what t.
Next steps1 lessons
  1. 114What Next?Build a SwiftUI app that fetches data, stores it and runs on a device.