Skip to content

Instantly share code, notes, and snippets.

@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: "blue@gmail.com", username: "green")
@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])")
import UIKit
var greeting = "Hello, playground"
// Basic Math
let num1 = 3
let num2 = 4
// add
import UIKit
// LOOPS can be used for ranges and arrays
// example
let ages = 1...6
for age in ages {
print("Age \(age)")
import UIKit
// Functions
func hi() {
print("Hi")
}
hi();
import UIKit
// Closures
// You can assign functions to a variable in swift
let work = {
print("Working")
}
work()
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
// Structs
struct Music {
var song: String
let time: Int
}
var goodMusic = Music(song: "Blues", time: 33)
import UIKit
// You can create our own initializer with structs
struct Dog {
var name: String
var age = 0
init(name: String) {
@phptuts
phptuts / App.js
Last active May 11, 2022 06:23
React JS Crash Course
import Header from './components/Header';
import Footer from './components/Footer';
import About from './components/About';
import { BrowserRouter as Router, Route, Routes } from 'react-router-dom';
import { useState, useEffect } from 'react';
import Home from './components/Home';
function App() {
const [tasks, setTasks] = useState([]);