This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import UIKit | |
| class FeedViewController: UIViewController{ | |
| var loadFeed: ((([String]) -> Void) -> Void)! | |
| convenience init(loadFeed: @escaping (([String]) -> Void) -> Void){ | |
| self.init() | |
| self.loadFeed = loadFeed | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension Optional where Wrapped == String{ | |
| var orEmpty: String{ | |
| switch self{ | |
| case .some(let value): | |
| return value | |
| case .none: | |
| return "" | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // ViewController.swift | |
| // Pokemon | |
| // | |
| // Created by Ihwan ID on 04/02/21. | |
| // | |
| import UIKit | |
| import Combine |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // MotivasiHarianWidget.swift | |
| // MotivasiHarianWidget | |
| // | |
| // Created by Ihwan ID on 13/01/21. | |
| // | |
| import WidgetKit | |
| import SwiftUI | |
| import Intents |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct ContentView: View { | |
| var body: some View { | |
| TabView { | |
| Text("Home Page") | |
| .tabItem { | |
| Image(systemName: "house.fill") | |
| Text("Homeb") | |
| } | |
| Text("Favorite Page") | |
| .tabItem { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | |
| } |