Comment on page
A1: Swift Basics
Original Author: Vin Bui
Assignment Due: Tuesday October 17, 2023 11:59pm
The goal of this assignment is to help you become familiar with basic Swift syntax and version control with Git and GitHub.
- How to implement functions according to a specification
- How to read documentation from outside resources
- How to read, create, and use functions to organize code
- How to work with Git and GitHub for version control
- How to use string interpolation to combine variables with strings
- How to convert data types using type casting
- How to create and work with arrays and dictionaries
- How to use conditionals to control program flow
- How to use methods provided by Swift
- How to use loops to repeat code
- How to work with optionals
- How to use higher order functions to simplify code
As with any other course at Cornell, the Code of Academic Integrity will be enforced in this class. All University-standard Academic Integrity guidelines should be followed. This includes proper attribution of any resources found online, including anything that may be open-sourced by AppDev. The University guidelines for Academic Integrity can be found here.
This assignment must be done individually. However, we do encourage limited collaboration. You are also free to come to the instructors or any course staff for help. Programming forums like Stack Overflow or Hacking with Swift are allowed as long as you understand the code and are not copying it exactly. Code written through AI means such as ChatGPT is NOT ALLOWED. However, you may use these resources for assistance, although we highly encourage consulting Ed Discussion or office hours instead.
If you are stuck or need a bit of guidance, please make a post on Ed Discussion or visit office hours. Please do not publicly post your code on Ed Discussion. If you are using an external resource such as Stack Overflow, keep in mind that we are using UIKit with Swift 5. If you see anything with @IBOutlet or any weird syntax, then you are most likely looking at a different version.
The grading for TODOs 1-9 are based on the number of test cases that you pass. We will convert the values to a decimal and their sum will be your subtotal (out of 10). The feedback form link is located in the Submission section of this handout.
First, if you have not installed Git yet, please do so now. You can follow the guide here. Then, watch this very short video about Git. If you are still confused, that is totally fine. You will understand it better as you use it. For the sake of time, I will quickly go over everything about Git and GitHub that you need for this and future assignments. If you are interested in learning more in depth (highly recommended), feel free to read our guide here.
Git is a version control system. You can think of this as Google Drive but for code. Your code is stored in a “folder” called a repository. For every assignment, we will provide the repository for you. You will clone this repository from GitHub using
git clone [CLONE URL]. You can think of GitHub as a library containing a bunch of repositories. Cloning a repository is like checking out a book.
Git and GitHub are not the same. You can think of GitHub as the library that manages the Git repositories (the books). When you clone a repository, the files could be brand new or have already been modified by someone else. Think of this as checking out a book that may have already been written in by another person who previously checked out the book.
Now, with that repository, you can do whatever you want to it— edit the files, create new files, delete old files, etc. Once you have done whatever you needed to do, you can send it back to the GitHub repository where it can store and keep track of the changes you have made. First, you need to stage your changes. In other words, tell Git what files to upload to GitHub. You can use the command
git add .to stage your changes.
Okay, so once you’ve selected the files you wanted to upload, now you need to wrap these files into a box with a message about the contents. This is known as making a commit. You are committing to send these files back to the GitHub repository. You can use the command
git commit -m "YOUR MESSAGE HERE"to make a commit.
So you’ve selected your items and wrapped it into a box with a message about the items. Now it is time to send that box to GitHub. All you have to do is type the command
That’s it! When working on these assignments, remember these 3 things:
git add .
git commit -m "YOUR MESSAGE HERE"
Now that you have a brief understanding about how we will be using Git and GitHub for assignments, please navigate to a folder on your device where you will keep all of your assignments. You can navigate to the folder using
Please clone the repository on GitHub: (Replace NETID with your NetID)
git clone email@example.com:cs1998-601-fa23/NETID-a1.git
If you are lost or getting any kind of error, create a post on Ed Discussion or come to office hours.
Navigate to the repository located on your local computer drive. Inside of the folder
NETID-a1should contain an Xcode project called
A1.xcodeproj. Open up the project.
Once you have the project opened, on the left side of the screen you should see the Navigator which contains all of the folders and files in the directory. If not, press
CMD + 0(that’s a zero) on your keyboard.
If you expand everything underneath
A1you should see the following:
You will be working on
You will be implementing the functions provided in this file. There are a total of 9 TODOs. If you click on this red box at the top of your Xcode, there should be a dropdown menu.
If you click on the clipboards, you will directed to the TODOs. The stars (⭐️) represent the difficulty level of each function. At the top of each function header is the specification. Your goal is to implement the function according to the specification. DO NOT CHANGE THE FUNCTION HEADER. We have given you hints to help you complete the tasks.
This file contains the test cases for each function. DO NOT EDIT THIS FILE.
There are two ways to run the test cases:
- 1.You can run the entire test suite by clicking on the button in the blue box next to
final class A1Tests: XCTestCasein the Editor or
A1Testsin the Navigator on the left.
- 2.You can run test cases for a specific function by clicking on the button in the blue box next to the function (such as
func testIntroduce()) in the Editor or in the Navigator on the left.
When you run the test suite for the first time, it may take about 30 seconds to 1 minute to load. After the first launch, it should not take that long. If the Simulator opens up, keep it open as it is required to run the test suite (for some reason). You will get a popup saying “Build Succeeded”, but this does not mean that you have passed the test cases. A passed test case will have green checkmarks and no error messages.
The yellow box above indicates an error message. The value pointed by the pink arrow is the “Received” output which is what your implementation returned. The value pointed by the green arrow is the “Expected” output which is what your function should return. The console will also output the error message.
Make sure you are using an iPhone simulator at the top of Xcode.
There are a total of 9 functions that you need to implement with varying levels of difficulty (indicated by a ⭐️). Follow these steps when working on the assignment:
- 1.Begin TODO 1 and implement the function.
- 2.Run the test function for TODO 1. If failed, fix your function and try again. If passed, move on to the next step.
- 3.Stage, commit, and push your changes to GitHub. In terminal, make sure you are in your working directory. Run these commands in the following order:
git add .
git commit -m "YOUR MESSAGE HERE"
- A good message could be “
Completed TODO 1: introduce"
- 4.Double check on the Cornell Enterprise GitHub that your changes have been updated. If you receive an errors, create a post on Ed Discussion or visit office hours.
- 5.Repeat for TODOs 2-9.
- 1.Double check that all of your files are properly pushed to GitHub.
- 2.Clone your repository into a separate folder on your local computer drive.
- 3.Run your project and make sure that your code does not crash and everything works as needed.
- 4.If you are satisfied, download this TXT file and fill it out. Make sure to use the Clone SSH path.