Skip to content

Instantly share code, notes, and snippets.

import UIKit
// You can pass a closure that requires a parameter
func todo(items: [String], process: (String) -> Void) {
for item in items {
process(item)
}
}
import UIKit
// Closures
// You can assign functions to a variable in swift
let work = {
print("Working")
}
work()
import UIKit
// Functions
func hi() {
print("Hi")
}
hi();
import UIKit
// LOOPS can be used for ranges and arrays
// example
let ages = 1...6
for age in ages {
print("Age \(age)")
import UIKit
var greeting = "Hello, playground"
// Basic Math
let num1 = 3
let num2 = 4
// add
@phptuts
phptuts / 100DaysOfSwiftDay2.swift
Created November 13, 2021 07:19
Day 2 of 100 days of swift
import UIKit
// Arrays
// Most common type
// Stores order
let forecastTemp = [77, 32.3, 43.3]
print("Day 1: \(forecastTemp[0])")
@phptuts
phptuts / swift-structs.swift
Created October 27, 2021 23:57
Swift Structs Demo
import UIKit
struct User {
var email: String
var username: String
}
// Structs come with a prebuilt init function
var user = User(email: "[email protected]", username: "green")
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Dynamic Javascript Webpage?</title>
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Roboto:300,300italic,700,700italic"
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" href="https://glitch.com/favicon.ico" />
<title>Change CSS with JS Picture Changer</title>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
@phptuts
phptuts / funky_circles.js
Last active March 24, 2021 07:00
Funky Circles is a way of drawing crazy circles on top of a selfy
// Copy this into the p5.js editor
// https://editor.p5js.org/
let capture;
let circles = [];
let timeToChangeSeconds = 0.2;
let changeColorTime;