Skip to content

Instantly share code, notes, and snippets.

View myawesomehub's full-sized avatar
💛
Exploring

Mohammad Yasir myawesomehub

💛
Exploring
View GitHub Profile
@myawesomehub
myawesomehub / RecursionPrograms.swift
Created November 27, 2021 19:35
This gist contains few recursion programs
func binarySearchWithRecursion(arr: [Int], target: Int, s: Int, e: Int) -> Int {
if s > e {
return -1
}
if arr[s] == target {
return s
}
let med = e / arr.count
@myawesomehub
myawesomehub / Extension.swift
Created October 7, 2021 14:09
A Calendar Extension
extension Calendar {
public func getAllDates(
dateInterval: DateInterval,
dateComponent: DateComponents) -> [Date] {
var dates: [Date] = []
dates.append(dateInterval.start)
enumerateDates(startingAfter: dateInterval.start, matching: dateComponent, matchingPolicy: .nextTime) { date, _, stop in
guard let date = date else {
class ViewModel : ObservableObject {
@Published var weatherData : WeatherResponse?
@Published var showErrorAlert = false
@Published var alertDescription = ""
let city = "https://api.openweathermap.org/data/2.5/weather?q=delhi&appid={YOUR-API-KEY}&units=metric"
init(){
WeatherService.getData(city: city) { result in
enum NetworkError : Error {
case cityNotFound
case timeOut
}
class WeatherService {
static func getData(city : String , completionHandler : @escaping (Result<WeatherResponse, NetworkError>) -> ()) {
guard let url = URL(string: "\(city)") else {
class ViewModel : ObservableObject {
@Published var temp : Double
init(){
temp = 0
getData()
}
func getData() {
struct WeatherResponse : Decodable {
let name : String
let weather : [WeatherAPI]
let main : MainAPI
}
struct WeatherAPI : Decodable {
let description : String
}
class SomeClass: SomeSuperclass, MyProtocol, AnotherProtocol {
// class definition goes here
}
var myClosure = { (name : String) in
print("Mycoluuure\(name)")
}
myClosure("yasir")
// Mark:- First Point
private func addingOf(_ num1: Int, and num2: Int) {
print("\(num1) + \(num2) = \(num1 + num2)")
}
// Mark:- Second Point
private func increment(_ value: inout Int) {
value += 1
print(value)
}
@myawesomehub
myawesomehub / readme.md
Created June 17, 2021 11:41 — forked from benstr/readme.md
Gist Markdown Cheatsheet

#Heading 1 ##Heading 2 ###Heading 3 ####Heading 4 #####Heading 5 ######Heading 6


Paragraph