Skip to content

Swift Live Coding Playground is a curated collection of Swift code examples for live coding sessions and interactive learning. It covers topics from basic syntax and string interpolation to advanced concepts like closures, async/await, generics, protocols, and ARC. Each example includes detailed README comments and multiple use cases, making it ide

Notifications You must be signed in to change notification settings

talezion/SwiftPlayground

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Swift Live Coding Playground

This repository contains a comprehensive set of Swift code examples designed for a live coding session. Each section is built around a slide concept covering various Swift topics—from the basics to more advanced concepts. The examples are enriched with detailed README comments, demonstrating multiple use cases and scenarios to help you understand and teach Swift effectively.

Table of Contents

Overview

This repo is intended for educators and developers alike. It provides rich, hands-on examples covering a wide range of Swift topics, including:

  • Basic syntax and string interpolation
  • Arithmetic operations and operator overloading
  • Advanced collection operations with arrays, dictionaries, and sets
  • Control flow mechanisms like conditionals, loops, and switches
  • Function definitions with various parameter types and return values
  • Extensive coverage of closures, including callbacks and asynchronous usage
  • Working with enums, structs, and classes to build data models
  • Property observers and computed properties
  • Methods, subscripts, inheritance, and initialization/deinitialization
  • Error handling with custom error types
  • Swift’s new concurrency model with async/await
  • Type casting, nested types, extensions, protocols, and generics
  • Advanced topics like opaque types, ARC, and access control

Each section is self-contained and includes comprehensive examples to help you run, modify, and experiment with the code during your live session.

Slides and Code Examples

Below is an overview of each slide. You can find the corresponding code in this repo.

Slide 1: The Basics of Swift

  • Introduces constants (let) and variables (var), string interpolation, and basic printing.

Slide 2: Basic Operators

  • Demonstrates arithmetic operators and custom operator overloading.

Slide 3: Strings and Characters

  • Covers string manipulations like uppercase/lowercase conversion, concatenation, and character counting.

Slide 4: Collection Types

  • Explores arrays, dictionaries, and sets with operations like sorting, filtering, and union/intersection.

Slide 5: Control Flow

  • Showcases conditionals, loops, and switch statements to manage execution flow.

Slide 6: Functions

  • Covers function declarations, external parameter names, default parameters, variadic functions, and tuple returns.

Slide 7: Closures

  • Demonstrates using closures with sorted, filter, map, and asynchronous callbacks with @Sendable annotations.

Slide 8: Enumerations

  • Explains enums with raw values, associated values, and computed properties.

Slide 9: Structures and Classes

  • Compares value types (structs) and reference types (classes) and demonstrates their behavior differences.

Slide 10: Properties

  • Covers stored, computed properties and property observers (didSet).

Slide 11: Methods

  • Demonstrates instance methods, as well as static methods.

Slide 12: Subscripts

  • Explains read-only and read-write subscripts for custom data access.

Slide 13: Inheritance

  • Shows class inheritance with method overriding.

Slide 14: Initialization

  • Demonstrates failable initializers and convenience initializers.

Slide 15: Deinitialization

  • Explains how deinitializers are used to clean up resources.

Slide 16: Optional Chaining

  • Demonstrates safe access to nested optionals using optional chaining.

Slide 17: Error Handling

  • Covers throwing and catching custom errors using do-try-catch blocks.

Slide 18: Swift Concurrency Basics

  • Demonstrates async/await, running asynchronous tasks, and concurrent execution.

Slide 21: Type Casting

  • Explains safe downcasting using as? and type checking with is.

Slide 22: Nested Types

  • Shows how to organize code with nested enums, structs, and classes.

Slide 23: Extensions

  • Demonstrates extending built-in types with additional methods and computed properties.

Slide 24: Protocols & Protocol Extensions

  • Covers defining protocols, providing default implementations, and conforming to protocols.

Slide 25: Generics

  • Provides examples of generic functions and generic types.

Slide 25A: Protocol Generics with Associated Types

  • Demonstrates protocols with associated types to create flexible, type-safe interfaces.

Slide 26: Opaque and Boxed Protocol Types

  • Explains opaque return types using the some keyword.

Slide 27: Automatic Reference Counting (ARC)

  • Demonstrates ARC, strong/weak references, and how memory is managed.

Slide 29: Access Control

  • Covers access modifiers (public, internal, fileprivate, private) and encapsulation.

Usage

  1. Clone the Repository:
   git clone https://github.com/yourusername/SwiftLiveCodingPlayground.git
  1. Open the Project:
    Open the playground file(s) in Xcode to run and interact with the examples.

  2. Explore and Modify:
    Each section contains comprehensive code examples with detailed README comments. Feel free to modify or extend the examples for your live coding session.

Contributing

Contributions are welcome! If you have suggestions or improvements, please open an issue or submit a pull request. Whether you want to add new examples or refine existing ones, your contributions help improve this resource for the community.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Enjoy your live coding session and happy coding!

About

Swift Live Coding Playground is a curated collection of Swift code examples for live coding sessions and interactive learning. It covers topics from basic syntax and string interpolation to advanced concepts like closures, async/await, generics, protocols, and ARC. Each example includes detailed README comments and multiple use cases, making it ide

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages