This file contains 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 Foundation | |
func formatDuration(_ durationInSeconds: Int) -> String { | |
let (hours, secondsAfterHours) = divmod(durationInSeconds, 3600) | |
let (minutes, seconds) = divmod(secondsAfterHours, 60) | |
return String(format: "%02d:%02d:%02d", hours, minutes, seconds) | |
} | |
func divmod(_ numerator: Int, | |
_ denominator: Int) -> (quotient: Int, remainder: Int) { |
This file contains 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 isLeapYear(_ year: Int) -> Bool { | |
if year % 4 != 0 { | |
print("The year \(year) is not leap year because it is not evenly divisible by 4.") | |
return false | |
} else if year % 100 != 0 { | |
print("The year \(year) is a leap year because it is divisible by 4 and not by 100.") | |
return true | |
} else if year % 400 == 0 { | |
print("The year \(year) is a leap year because it is divisible by 400") | |
return true |
This file contains 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 CreditCardView: View { | |
var body: some View { | |
VStack(alignment: .leading, spacing: 20) { | |
HStack { | |
Text("Royale Gold Card") | |
.font(.system(size: 20, weight: .semibold, design: .monospaced)) | |
Spacer() | |
Image("american_ex") | |
.resizable() |
This file contains 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 UIView { | |
class func gradientViewWithText(text: String, size: CGSize, firstColor: UIColor, secondColor: UIColor, font: UIFont) -> UIView { | |
let view = UIView() | |
let layer = CAGradientLayer() | |
layer.colors = [firstColor.cgColor, secondColor.cgColor] | |
layer.frame = CGRect(x: 0, y: 0, width: size.width, height: size.height) | |
view.layer.addSublayer(layer) | |
let textLabel = UILabel() |
This file contains 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 | |
// MARK: - IndexPaths | |
extension UICollectionView { | |
var lastIndexPath: IndexPath? { | |
return lastIndexPath(inSection: lastSection) | |
} | |
var lastSection: Int { |
This file contains 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 Foundation | |
extension Date { | |
func timeAgo() -> String { | |
let secondsAgo = Int(Date().timeIntervalSince(self)) | |
let minute = 60 | |
let hour = 60 * minute |
This file contains 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 Stack<T>: CustomStringConvertible { | |
// array of items | |
var items: [T] = [] | |
// to print the formatted description | |
var description: String { | |
return "---- Stack begin ----\n" + | |
items.map({ "\($0)" }).joined(separator: "\n") + | |
"\n---- Stack End ----" |
This file contains 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
class BindingTextField: UITextField { | |
var textChangedHandler: (String) -> () = { _ in } | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
initialSetup() | |
} | |
required init?(coder: NSCoder) { |
This file contains 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 Foundation | |
enum NetworkError: Error { | |
case decodingError | |
case domainError | |
case urlError | |
} | |
enum HttpMethod: String { |
This file contains 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 Network | |
class NetworkReachability { | |
static let shared = NetworkReachability() | |
private var monitor: NWPathMonitor? | |
private var isMonitoring = false | |
// use it to notified that monitoring did start. | |
var didStartMonitoringHandler: (() -> Void)? |
NewerOlder