• Stars
    star
    225
  • Rank 177,187 (Top 4 %)
  • Language
    Swift
  • License
    MIT License
  • Created over 10 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Learning Swift by working through example code in playgrounds

Swift Playgrounds

Some experiments with Playgrounds in XCode 8.2 using the Swift programming language.

The Swift Programming Language Book

I have been working through all the examples in the book Apple Inc. β€œThe Swift Programming Language.” iBooks. https://itunes.apple.com/au/book/swift-programming-language/id881256329?mt=11. Each .playground file in the project relates to a chapter from the Swift Programming Language book.

I have implemented this as a single XCode project that contains a playground file for each chapter of the language reference book. I'm finding it quite useful to have this project open when I am writing Swift code as I can use the project wide search functionality to lookup any Swift features or syntax that I am unsure about (so long as I can remember the words to look for)

Below is a list of each of the files within the project (this is also a list of the chapters of the book that I have worked through).

  • A Swift Tour contains the code from the "Swift Tour" chapter. It touches on most of the unusual features of the language and is easy to search through to find examples. It is a large file and does tend to give the swift interpreter a rather hard time.

Chapters from the Language guide. Each chapter goes into depth about its particular subject.

  • The Basics This chapter covers basic value types like Strings, Ints, Bools and floats. The notation for exponent values in float literals is interesting. Comments are covered (nested /* */ comment blocks). TypeAlias is covered as are tuples. Optionals are touched on and assertions are mentioned.
  • Basic Operators Arithmetic, remainder, increment, decrement, comparison, unary, ternary, range (closed and half-closed) and logical operators. There are examples of all of them.
  • Strings And Characters Some details about Unicode literals (multi-byte characters). The countElements() function for finding the length of a string. Concatenating strings, Comparing strings and Interpolating strings (not much on splitting or parsing strings).
  • Collection Types
  • ControlFlow
  • Functions
  • Closures
  • Enumerations
  • Classes And Structures
  • Properties
  • Methods
  • Subscripts
  • Inheritance
  • Initialization
  • Deinitialization
  • Automatic Reference Counting
  • Optional Chaining
  • Type Casting
  • Nested Types
  • Extensions
  • Protocols
  • Generics
  • Advanced Operators

Using Swift with Cocoa and Objective-C Book

There are six playground files that work through the code in the β€œUsing Swift with Cocoa and Objective-C.” iBook. https://itunes.apple.com/au/book/using-swift-cocoa-objective/id888894773?mt=11. They are listed below. The example from this book didn't translate as well to the playgrounds as the previous book examples did.

  • Basic Setup
  • Interacting With Objective-C-
  • Writing Classes With Objective C Behaviour
  • Working With Cocoa Data Types
  • Adopting Cocoa Design Patterns
  • InteractingWith C

Swift Standard Library

The documentation for the Swift Standard Library can be found at the following link https://developer.apple.com/library/prerelease/ios/documentation/General/Reference/SwiftStandardLibraryReference/. There is a wealth of information contained in the standard library doc and it is nicely organised so that it is easy to experiment with in a playground environment. I have attempted to extend the examples somewhat to try and show off some of the other features of the standard library.

  • String
  • Array
  • Dictionary
  • NumericTypes
  • Protocols
  • FreeFunctions
  • Undocumented

Swift Blog

The Swift blog contains several articles detailing interesting information about the developing language.

  • 2014-08-15 Value and Reference Types
  • 2014-08-05 Boolean
  • 2014-07-28 Interacting with C Pointers
  • 2014-07-23 Access Control

NSHipster

Lots of great articles delving into the finer points of Cocoa programming. The recent articles on Swift are always interesting to go through

  • 2014-08-08 Swift Literal Convertibles Shows how you can create types of your own that can be written as literals when you use them.

What next?

Here are some links to other projects around the web that I would also like to implement

More Repositories

1

NSOutlineViewInSwift

A project to help me understand what is required to provide data for an NSOutlineView or Source List control
Swift
59
star
2

SICP-Exercises

Working through the SICP exercises in Racket and Swift
Swift
25
star
3

NSProgressInSwift

A sample project demonstrating some basic NSProgress usage (happens to be written in Swift)
Swift
14
star
4

NSTabViewControllerInSwift

A simple example of using a NSTabViewController in a Mac app (Sierra, Xcode 8.3, Using storyboards).
Swift
6
star
5

SwiftSerialPortSample

An attempt to convert Apples SerialPortSample project over to Swift
Swift
4
star
6

EISerialPort

A Cocoa serial port framework for rapidly developing apps that talk to micro-controllers.
Objective-C
2
star
7

Constraints

Experimenting with a constraint solver in Swift.
Swift
1
star
8

SwiftMatrix

Some experiments implementing a Matrix data type in Swift
Swift
1
star
9

DRPMakeingFriendsWithValueTypes

Little project to help me make sense of Andy Matuschak's talk "Controlling Complexity in Swift β€” or β€” Making Friends with Value Types"
Swift
1
star
10

CorePlotInSwift

Some simple references for how to use CorePlot with Swift
Objective-C
1
star
11

AVFoundationInSwift

Some simple code examples for doing things in AVFoundation using Swift.
Swift
1
star
12

EImsp430BSL

A Bootstrap Loader library for the MSP430 Microcontroller, written in Objective-C/Cocoa
Objective-C
1
star
13

PSoC-4-BLE-Experiments

A series of projects from the Cypress 100 projects in 100 days promotion for me to learn how to work with the PSoC 4 BLE chip. Includes Mac Apps where appropriate.
C
1
star
14

NSTableViewInSwift

A collection of projects demonstrating various methods of working with NSTableView in Swift.
Swift
1
star