Skip to content

Instantly share code, notes, and snippets.

Avatar

Ihwan IhwanID

View GitHub Profile
@IhwanID
IhwanID / news.json
Created Mar 8, 2022
Mock JSON NewsAPI
View news.json
{"status":"ok","totalResults":38,"articles":[{"source":{"id":null,"name":"Kompas.com"},"author":"Rendika Ferri Kurniawan","title":"Fakta-fakta 8 Planet di Tata Surya dan Kemungkinan Planet Kesembilan - Kompas.com - KOMPAS.com","description":"Ada planet-planet yang bergerak tak searah jarum jam, bahkan porosnya miring. Ada juga yang berwarna merah tapi justru dingin. Ini fakta-fakta planet.","url":"https://www.kompas.com/tren/read/2022/03/08/193100965/fakta-fakta-8-planet-di-tata-surya-dan-kemungkinan-planet-kesembilan","urlToImage":"https://asset.kompas.com/crops/zJuFpHFHSpTLKGj4GElqaUkMx1s=/150x4:835x460/780x390/filters:watermark(data/photo/2020/03/10/5e6775d554370.png,0,-0,1)/data/photo/2021/04/19/607cec3127dfa.jpg","publishedAt":"2022-03-08T12:31:00Z","content":null},{"source":{"id":null,"name":"Kompas.com"},"author":"Reska K. Nistanto","title":"Cara Nonton Apple Event Malam Ini, iPhone SE 3 Bakal Meluncur? - Kompas.com - Tekno Kompas.com","description":"Apple akan menggelar acara peluncuran bertajuk 'Peek
@IhwanID
IhwanID / test.swift
Created Aug 27, 2021
Track Memory Leaks Unit Test with XCTestCase Extension
View test.swift
import XCTest
extension XCTestCase{
func trackMemoryLeaks(_ instance: AnyObject, file: StaticString = #file, line: UInt = #line){
addTeardownBlock { [weak instance] in
XCTAssertNil(instance, "Instance should have been deallocated. Potential memory leak.", file: file, line: line)
}
}
}
@IhwanID
IhwanID / main.swift
Last active Aug 17, 2021
Intro to Dependency Diagrams and Composition
View main.swift
import UIKit
class FeedViewController: UIViewController{
var loadFeed: ((([String]) -> Void) -> Void)!
convenience init(loadFeed: @escaping (([String]) -> Void) -> Void){
self.init()
self.loadFeed = loadFeed
}
@IhwanID
IhwanID / main.swift
Created Mar 15, 2021
For Where in Swift
View main.swift
let numbers = [1, 2, 3 , 4 , 5, 6]
for number in numbers{
if number.isMultiple(of: 2){
print(number)
}
}
for number in numbers where number.isMultiple(of: 2){
print(number)
@IhwanID
IhwanID / Optional+Ext.swift
Created Mar 15, 2021
String OrEmpty Optional Extension
View Optional+Ext.swift
extension Optional where Wrapped == String{
var orEmpty: String{
switch self{
case .some(let value):
return value
case .none:
return ""
}
}
}
@IhwanID
IhwanID / main.swift
Last active Feb 5, 2021
Combine Many Merge Pokemon API
View main.swift
//
// ViewController.swift
// Pokemon
//
// Created by Ihwan ID on 04/02/21.
//
import UIKit
import Combine
@IhwanID
IhwanID / main.swift
Created Jan 31, 2021
Two Sum in Swift
View main.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 Jan 30, 2021
Get Most Common Element in Array
View main.swift
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 Jan 13, 2021
Daily Motivation WidgetKit SwiftUI
View MotivasiHarianWidget.swift
//
// MotivasiHarianWidget.swift
// MotivasiHarianWidget
//
// Created by Ihwan ID on 13/01/21.
//
import WidgetKit
import SwiftUI
import Intents
@IhwanID
IhwanID / ContentView.swift
Created Jan 10, 2021
Create Tab Bar in SwiftUI
View ContentView.swift
struct ContentView: View {
var body: some View {
TabView {
Text("Home Page")
.tabItem {
Image(systemName: "house.fill")
Text("Homeb")
}
Text("Favorite Page")
.tabItem {