Skip to content

Instantly share code, notes, and snippets.

@afinarv
afinarv / gist:59dfbe5e2e6416d79bba1324b6f24c8b
Last active February 23, 2024 02:35
SpriteKitHelperThings
import SwiftUI
import SpriteKit
struct GameView: View {
@ObservedObject var gameScene = GameScene()
var scene: SKScene {
let scene = gameScene
scene.scaleMode = .resizeFill
scene.anchorPoint = CGPoint(x: 0.5, y: 0.5)
@afinarv
afinarv / LoopPlayground.swift
Last active April 5, 2023 02:00
Examples and exercises to understand loop in swift
import Foundation
/*
Loop is used to iterate over a sequence, such as items in an array, ranges of numbers, or characters in a string.
Loop will execute a block of code repeatedly, as long as certain conditions are met.
*/
let vegDrawer = ["🫑", "🍅", "🥕", "🥬", "🥦"]
func foodPrep(veg: String) {
import UIKit
var greeting = "Hello, playground"
var today = "Sunday" //assigning value
if today == "Friday" { //ngecek
print("Play 'Last Friday Night' by Katy Perry")
} else if today == "Sunday" {
print("Play 'Sunday Morning' by Maroon Five")
/*
This is the lyric of Baby Shark:
-----
Baby shark, doo doo doo doo doo doo
Baby shark, doo doo doo doo doo doo
Baby shark, doo doo doo doo doo doo
Baby shark!
Mommy shark, doo doo doo doo doo doo
Mommy shark, doo doo doo doo doo doo
/* 1.
This is the lyric of Finger Family:
-----
daddy finger, daddy finger
where are you?
here I am, here I am
how do you do?
mommy finger, mommy finger
import UIKit
/* 1.
Some people LOVE music. They listen to music almost all the time, more than 50 times per day. Let's call them the 'Music Junkie'.
Some other occasionally listen to music. They listen to music 10 to 50 times per day. Let's call them the 'Music Enjoyer'.
And some other choose not to have music at all. So, zero times. Let's call them 'No-music Folk'.
|-------------------- |--------------------------------- |
|numberOfPlayedMusic | Print Result |
|-------------------- |--------------------------------- |
@afinarv
afinarv / SwiftConditionIntro.swift
Created March 30, 2022 00:31
Learning basic condition & function in Swift
var today = "Wednesday"
//1. if
if today == "Friday" {
print("Play 'Last Friday Night' by Katy Perry")
}
//2. if-else
if today == "Friday" {
print("Play 'Last Friday Night' by Katy Perry")
@afinarv
afinarv / AudioHelper.swift
Created October 24, 2021 16:35
AudioHelper to simplify audio
import Foundation
import AVFoundation
class AudioHelper: NSObject, AVAudioPlayerDelegate {
var player: AVAudioPlayer?
class var defaultHelper: AudioHelper {
struct Static {
static let instance: AudioHelper = AudioHelper()
}
class MainTabBarController: UITabBarController {
var homeViewController: HomeViewController!
var secondViewController: MarketplaceViewController!
var serviceViewController: PartnerListViewController!
var actionViewController: UIViewController!
var thirdViewController: JobListViewController!
var fourthViewController: MenuViewController!
override func viewDidLoad() {
func createNavController(root: UIViewController) -> UINavigationController{
let navController = UINavigationController(rootViewController: root)
navController.navigationBar.layer.masksToBounds = false
navController.navigationBar.layer.shadowColor = UIColor.lightGray.cgColor
navController.navigationBar.layer.shadowOpacity = 0.5
navController.navigationBar.layer.shadowOffset = CGSize(width: 0, height: 2.0)
navController.navigationBar.layer.shadowRadius = 5
return navController
}