Skip to content

Instantly share code, notes, and snippets.

View IhwanID's full-sized avatar

Ihwan IhwanID

View GitHub Profile
@IhwanID
IhwanID / main.swift
Created January 31, 2021 06:26
Two Sum in Swift
func twoSum(_ nums: [Int], _ target: Int) -> [Int] {
var dictionary = [Int:Int]();
for index in 0 ..< nums.count {
let complement = target - nums[index];
if dictionary.keys.contains(complement) && dictionary[complement] != index {
return [dictionary[complement]!,index];
}
dictionary[nums[index]] = index
}
@IhwanID
IhwanID / main.swift
Created January 30, 2021 15:49
Get Most Common Element in Array
var colorArray = ["blue", "white", "yellow", "red","blue", "white", "yellow", "red","blue", "white", "yellow", "red","blue", "white", "yellow", "red","blue", "white", "yellow", "red","yellow", "red","yellow", "red","yellow", "red", "red"]
func getMostColor(input: [String]) -> String{
var topColor: String = ""
var colorDict: [String:Int] = [:]
for color in input{
colorDict[color, default:0]+=1
}
@IhwanID
IhwanID / MotivasiHarianWidget.swift
Created January 13, 2021 09:26
Daily Motivation WidgetKit SwiftUI
//
// MotivasiHarianWidget.swift
// MotivasiHarianWidget
//
// Created by Ihwan ID on 13/01/21.
//
import WidgetKit
import SwiftUI
import Intents
@IhwanID
IhwanID / ContentView.swift
Created January 10, 2021 01:25
Create Tab Bar in SwiftUI
struct ContentView: View {
var body: some View {
TabView {
Text("Home Page")
.tabItem {
Image(systemName: "house.fill")
Text("Homeb")
}
Text("Favorite Page")
.tabItem {
@IhwanID
IhwanID / ContentView.swift
Last active January 10, 2021 01:13
SwiftUI List
struct ContentView: View {
var body: some View {
let rangga = Student(name: "Rangga", age: 18)
let andi = Student(name: "Andi",age: 19)
let ihwan = Student(name: "Ihwan", age: 20)
let students = [rangga, andi, ihwan]
return List(students) { student in
StudentRow(student: student)
}
@IhwanID
IhwanID / main.swift
Created January 9, 2021 16:49
Example Using Webview In SwiftUI
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView{
SwiftUIWebView(url: URL(string: "https://ihwan.id"))
}
}
}
@IhwanID
IhwanID / main.swift
Created January 9, 2021 16:24
Tab Bar SwiftUI
struct ContentView: View {
var body: some View {
TabView {
Text("Home Page")
.tabItem {
Image(systemName: "house.fill")
Text("Homeb")
}
Text("Favorite Page")
.tabItem {
@IhwanID
IhwanID / ViewController.swift
Created December 27, 2020 12:38
OnBoard Swift UIKit Programmatically
//
// ViewController.swift
// run
//
// Created by Ihwan ID on 30/03/20.
// Copyright © 2020 Ihwan ID. All rights reserved.
//
import UIKit
@IhwanID
IhwanID / SwiftUIWebView.swift
Created December 13, 2020 07:14
SwiftUI Webview Using WKWebView & Webkit
//
// WebView.swift
// SwiftUIWebView
//
// Created by Ihwan ID on 13/12/20.
//
import SwiftUI
import WebKit
@IhwanID
IhwanID / api.json
Last active November 3, 2020 15:27
{
"user": {
"name": "Pak Bedu",
"email": "[email protected]"
},
"children": [
{
"id": 123,
"name": "Wahyu Amarulloh",
"balance": 7500,