Skip to content

Latest commit

 

History

History

Classic

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

100 Days of Swift

Challenges

Click to see Table of Contents

Day 1 - First Steps in Swift

Variables and Constants, Strings, Integers, Doubles and Booleans, Inference and Type Annotations but setting foundations.

Code

Day 2 - Complex Types

Arrays, Sets, Tuples, Dictionaries and Enumerations.

Code

Day 3 - Operators and Conditions

Arithmetic Operators, Operators Overloading, Compound Assignment Operators, Comparison Operators, Conditions, Combining Conditions, The Ternary Operator, Switch Statements and Range Operators.

Code

Day 4 - Looping

For loops, While loops, Repeat loops, Exiting loops, Exiting multiple loops, Skipping items and Infinite loops.

Code

Day 5 - Functions

Writing functions, Accepting parameters, Returning values, Parameter labels, Omitting parameter labels, Default parameters, Variadic functions, Writing throwing functions, Running throwing functions and inout parameters.

Code

Day 6 - Closures, Part One

Creating basic closures, Accepting parameters in a closure, Returning values from a closure, Closures as parameters and Trailing closure syntax.

Code

Day 7 - Closures, Part Two

Using closures as parameters when they accept parameters, Using closures as parameters when they return values, Shorthand parameter names, Closures with multiple parameters, Returning closures from functions and Capturing values.

Code

Day 8 - Structs, Part One

Creating your own structs, Computed properties, Property observers, Methods, Mutating methods, Properties and methods of strings and Properties and methods of arrays.

Code

Day 9 - Structs, Part Two

Initializers, Referring to the current instance, Lazy properties, Static properties and methods and Access control.

Code

Day 10 - Classes

Creating your own classes, Class inheritance, Overriding methods, Final classes, Copying objects, Deinitializers and Mutability.

Code

Day 11 - Protocols And Extensions

Protocols, Protocol inheritance, Extensions, Protocol extensions and Protocol-oriented programming.

Code

Day 12 - Optionals

Handling missing data, Unwrapping optionals, Unwrapping with guard, Force unwrapping, Implicitly unwrapped optionals, Nil coalescing, Optional chaining, Optional try, Failable initializers and Typecasting.

Code

Day 13 - Swift Review, Day One

Variables and Constants, Types of Data, Operators, String Interpolation, Arrays, Dictionaries, Conditional Statements, Loops and Switch Case.

Code

Day 14 - Swift Review, Day Two

Functions, Optionals, Optional Chaining, Enumerations, Structs and Classes.

Code

Day 15 - Swift Review, Day Three

Properties, Static properties and methods, Access control, Polymorphism and typecasting and Closures.

Code

Day 16 - Project 1, Part One

Setting Up, Listing Images with FileManager and Designing Our Interface.

Code

Day 17 - Project 1, Part Two

Building a detail screen, Loading images with UIImage and Final tweaks: hidesBarsOnTap, safe area margins.

Code

Day 18 - Project 1, Part Three

Challenge

  1. Use Interface Builder to select the text label inside your table view cell and adjust its font size to something larger – experiment and see what looks good.
  2. In your main table view, show the image names in sorted order, so “nssl0033.jpg” comes before “nssl0034.jpg”.
  3. Rather than show image names in the detail title bar, show “Picture X of Y”, where Y is the total number of images and X is the selected picture’s position in the array. Make sure you count from 1 rather than 0.

Code

Day 19 - Project 2, Part One

Setting up, Designing your layout and Making the basic game work: UIButton and CALayer.

Code

Day 20 - Project 2, Part Two

Guess which flag: random numbers and From outlets to actions: creating an IBAction.

Code

Day 21 - Project 2, Part Three

Challenge

  1. Try showing the player’s score in the navigation bar, alongside the flag to guess.
  2. Keep track of how many questions have been asked, and show one final alert controller after they have answered 10. This should show their final score.
  3. When someone chooses the wrong flag, tell them their mistake in your alert message – something like “Wrong! That’s the flag of France,” for example.

Code

Day 22 - Project 3

About technique projects and UIActivityViewController explained.

Challenge

  1. Try adding the image name to the list of items that are shared. The activityItems parameter is an array, so you can add strings and other things freely. Note: Facebook won’t let you share text, but most other share options will.
  2. Go back to project 1 and add a bar button item to the main view controller that recommends the app to other people.
  3. Go back to project 2 and add a bar button item that shows their score when tapped.

Code

Day 23 - MILESTONE: Projects 1-3

Challenge

The challenge is to create an app that lists various world flags in a table view.

When one of them is tapped, slide in a detail view controller that contains an image view, showing the same flag full size. On the detail view controller, add an action button that lets the user share the flag picture and country name using UIActivityViewController.

Code

Day 24 - Project 4, Part One

Setting up, Creating a simple browser with WKWebView and Choosing a website: UIAlertController action sheets.

Code

Day 25 - Project 4, Part Two

Monitoring page loads: UIToolBar and UIProgressView and Refactoring for the win.

Code

Day 26 - Project 4, Part Three

Challenge

  1. If users try to visit a URL that isn’t allowed, show an alert saying it’s blocked.
  2. Try making two new toolbar items with the titles Back and Forward. You should make them use webView.goBack and webView.goForward.
  3. For more of a challenge, try changing the initial view controller to a table view like in project 1, where users can choose their website from a list rather than just having the first in the array loaded up front.

Code

Day 27 - Project 5, Part One

Setting up, Reading from disk: contentsOfFile and Pick a word, any word: UIAllertController.

Code

Day 28 - Project 5, Part Two

Prepare for submission: lowercased() and IndexPath, Checking for valid answers and Or else what?

Code

Day 29 - Project 5, Part Three

Challenge

  1. Disallow answers that are shorter than three letters or are just our start word.
  2. Refactor all the else statements we just added so that they call a new method called showErrorMessage().
  3. Add a left bar button item that calls startGame(), so users can restart with a new word whenever they want to.
  • Bonus: Fix a bug that happens when you introduce the same word with and without uppercase letters.

Code

Day 30 - Project 6, Part One

Setting up, Advanced Auto Layout and Auto Layout in code: addConstraints() with Visual Format Language.

Code

Day 31 - Project 6, Part Two

Auto Layout metrics and priorities: constraints(withVisualFormat:), Auto Layout anchors and Wrap up.

Code

Day 32 - MILESTONE: Projects 4-6

Challenge

The challenge is to create an app that lets people create a shopping list by adding items to a table view.

Code

Day 33 - Project 7, Part One

Creating the basic UI: UITabBarController and Parsing JSON using the Codable protocol.

Code

Day 34 - Project 7, Part Two

Rendering a petition: loadHTMLString and Finishing touches: didFinishLaunchingWithOptions.

Code

Day 35 - Project 7, Part Three

Challenge

  1. Add a Credits button to the top-right corner using UIBarButtonItem. When this is tapped, show an alert telling users the data comes from the We The People API of the Whitehouse.
  2. Let users filter the petitions they see. This involves creating a second array of filtered items that contains only petitions matching a string the user entered. Use a UIAlertController with a text field to let them enter that string. This is a tough one, so I’ve included some hints below if you get stuck.

Code

Day 36 - Project 8, Part One

Setting up and Building a UIKit user interface programmatically.

Code

Day 37 - Project 8, Part Two

Loading a level and adding button targets, firstIndex(of:) and joined() and Property observers: didSet.

Code

Day 38 - Project 8, Part Three

Challenge

  1. Draw a thin gray line around the buttons view, to make it stand out from the rest of the UI.
  2. If the user enters an incorrect guess, show an alert telling them they are wrong.
  3. Try making the game also deduct points if the player makes an incorrect guess.

Code

Day 39 - Project 9, Part One

Beginning with Grand Central Dispatch

Code

Day 40 - Project 9, Part Two

Challenge

  1. Modify project 1 so that loading the list of NSSL images from our bundle happens in the background. Code
  2. Modify project 8 so that loading and parsing a level takes place in the background. Code
  3. Modify project 7 so that your filtering code takes place in the background. Code

Day 41 - MILESTONE: Projects 7-9

Challenge

The challenge is this: make a hangman game using UIKit.

Code

Day 42 - Project 10, Part One

Designing UICollectionView cells and implementing data sources.

Code

Day 43 - Project 10, Part Two

Importing photos with UIImagePickerController.

Code

Day 44 - Project 10, Part Three

Challenge

  1. Add a second UIAlertController that gets shown when the user taps a picture, asking them whether they want to rename the person or delete them.
  2. Use picker.sourceType = .camera when creating your image picker.
  3. Modify project 1 so that it uses a collection view controller rather than a table view controller.

Code

Day 45 - Project 11, Part One

Falling boxes with SKSpriteNode, UITouch and SKPhysicsBody.

Code

Day 46 - Project 11, Part Two

Spinning slots (SKAction), Collision detection (SKPhysicsContactDelegate) and Scores on the board (SKLabelNode).

Code

Day 47 - Project 11, Part Three

Special effects: SKEmitterNode.

Challenge

  1. Try writing code to use a random ball color each time they tap the screen.
  2. Try to force the Y value of new balls so they are near the top of the screen.
  3. Give players a limit of five balls, then remove obstacle boxes when they are hit.

Code

Day 48 - Project 12, Part One

Reading and writing basics: UserDefaults and Fixing Project 10: NSCoding.

Code

Day 49 - Project 12, Part Two

Fixing Project 10: Codable.

Challenge

  1. Modify project 1 so that it remembers how many times each storm image was shown. Code
  2. Modify project 2 so that it saves the player’s highest score, and shows a special message if their new score beat the previous high score. Code
  3. Modify project 5 so that it saves the current word and all the player’s entries to UserDefaults, then loads them back when the app launches. Code

Day 50 - MILESTONE: Projects 10-12

Challenge

The challenge is to put two different projects into one: I’d like you to let users take photos of things that interest them, add captions to them, then show those photos in a table view. Tapping the caption should show the picture in a new view controller, like we did with project 1. So, your finished project needs to use elements from both project 1 and project 12, which should give you ample chance to practice.

Code

Day 51 - Expanding Your Horizons

No code today! Instead, two interesting videos about map(), flatMap() and filter().

Day 52 - Project 13, Part One

Designing the interface and importing pictures from photo library.

Code

Day 53 - Project 13, Part Two

Applying filters: CIContext, CIFilter and saving to the iOS photo library.

Code

Day 54 - Project 13, Part Three

Challenge

  1. Try making the Save button show an error if there was no image in the image view.
  2. Make the Change Filter button change its title to show the name of the currently selected filter.
  3. Experiment with having more than one slider, to control each of the input keys you care about. For example, you might have one for radius and one for intensity.

Code

Day 55 - Project 14, Part One

Getting up and running: SKCropNode and Penguin, show thyself: SKAction moveBy(x:y:duration:).

Code

Day 56 - Project 14, Part Two

Whack to win: SKAction sequences

Challenge

  1. Record your own voice saying "Game over!" and have it play when the game ends.
  2. When showing “Game Over” add an SKLabelNode showing their final score.
  3. Use SKEmitterNode to create a smoke-like effect when penguins are hit, and a separate mud-like effect when they go into or come out of a hole.

Code

Day 57 - Project 15, Part One

Switch, case, animate: animate(withDuration:) and Transform: CGAffineTransform

Code

Day 58 - Project 15, Part Two

Challenge

  1. Go back to project 8 and make the letter group buttons fade out when they are tapped. We were using the isHidden property, but you'll need to switch to alpha because isHidden is either true or false, it has no animatable values between. Code
  2. Go back to project 13 and make the image view fade in when a new picture is chosen. To make this work, set the alpha to 0 first. Code
  3. Go back to project 2 and make the flags scale down with a little bounce when pressed. Code

Day 59 - MILESTONE: Projects 13-15

Challenge

Your challenge is to make an app that contains facts about countries: show a list of country names in a table view, then when one is tapped bring in a new screen that contains its capital city, size, population, currency, and any other facts that interest you. The type of facts you include is down to you – Wikipedia has a huge selection to choose from.

Code

Day 60 - Project 16, Part One

Setting up, Up and running with MapKit and Annotations and accessory views: MKPinAnnotationView

Code

Day 61 - Project 16, Part Two

Challenge

  1. Try typecasting the return value from dequeueReusableAnnotationView() so that it's an MKPinAnnotationView. Once that’s done, change the pinTintColor property to your favorite UIColor.
  2. Add a UIAlertController that lets users specify how they want to view the map. There's a mapType property that draws the maps in different ways. For example, .satellite gives a satellite view of the terrain.
  3. Modify the callout button so that pressing it shows a new view controller with a web view, taking users to the Wikipedia entry for that city.

Code

Day 62 - Project 17, Part One

Setting up, Space: the final frontier, Bring on the enemies: linearDamping, angularDamping and Making contact: didBegin()

Code

Day 63 - Project 17, Part Two

Challenge

  1. Stop the player from cheating by lifting their finger and tapping elsewhere – try implementing touchesEnded() to make it work.
  2. Make the timer start at one second, but then after 20 enemies have been made subtract 0.1 seconds from it so it’s triggered every 0.9 seconds. After making 20 more, subtract another 0.1, and so on. Note: you should call invalidate() on gameTimer before giving it a new value, otherwise you end up with multiple timers.
  3. Stop creating space debris after the player has died.

Code

Day 64 - Project 18, Part One

Setting up, Basic Swift debugging using print(), Debugging with assert(), Debugging with breakpoints and View debugging

Code

Day 65 - Project 18, Part Two

Challenge

  1. Temporarily try adding an exception breakpoint to project 1, then changing the call to instantiateViewController() so that it uses the storyboard identifier “Bad” – this will fail, but your exception breakpoint should catch it. Code
  2. In project 1, add a call to assert() in the viewDidLoad() method of DetailViewController.swift, checking that selectedImage always has a value. Code
  3. Go back to project 5, and try adding a conditional breakpoint to the start of the submit() method that pauses only if the user submits a word with six or more letters. Code

Review: Debug like a Pro

Day 66 - MILESTONE: Projects 16-18

Challenge

Make a shooting gallery game using SpriteKit: create three rows on the screen, then have targets slide across from one side to the other. If the user taps a target, make it fade out and award them points.

Some key points:

  • Make some targets big and slow, and others small and fast. The small targets should be worth more points.
  • Add “bad” targets – things that cost the user points if they get shot accidentally.
  • Make the top and bottom rows move left to right, but the middle row move right to left.
  • Add a timer that ticks down from 60 seconds. When it hits zero, show a Game Over message.
  • Try going to https://openclipart.org/ to see what free artwork you can find.
  • Give the user six bullets per clip. Make them tap a different part of the screen to reload.

Code

Day 67 - Project 19, Part One

Setting up, Making a shell app, Adding an extension: NSExtensionItem and What do you want to get?

Code

Day 68 - Project 19, Part Two

  • Establishing communication.
  • Editing multiline text with UITextView.
  • Fixing the keyboard: NotificationCenter

Code