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 array1 = [3,4,1,6,7,2,5,5] | |
for i in 1..<array1.count { | |
let a = array1[i] | |
var b = i-1 | |
while b >= 0 && array1[b] > a { | |
array1[b+1] = array1[b] | |
b -= 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
var array2 = [4,2,2,5,7,2,1,9,3] | |
func merge(left:[Int],right:[Int]) -> [Int] { | |
var mergedList = [Int]() | |
var l = left | |
var r = right | |
while l.count > 0 && r.count > 0 { | |
if l.first! < r.first! { |
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 myarray4 = [4,6,2,7,7,3,5] | |
func quickSort(array: inout [Int], startIndex: Int, endIndex: Int) { | |
if startIndex >= endIndex { | |
return | |
} | |
let pivot = partition(array: &array, startIndex: startIndex, endIndex: endIndex) | |
quickSort(array: &array, startIndex: startIndex, endIndex: pivot-1) | |
quickSort(array: &array, startIndex: pivot+1, endIndex: endIndex) |
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 WeatherData : Codable { | |
let name : String | |
let main : Main | |
let weather : [Weather] | |
} | |
struct Main : Codable { | |
let temp : Double | |
} |
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 Foundation | |
class WeatherManager : ObservableObject { | |
@Published var tempText : Double = 0.0 | |
@Published var conditionImage : Int = 0 | |
@Published var cityName = "" | |
let weatherURL = "https://api.openweathermap.org/data/2.5/weather?appid={YOUR API KEY}&units=metric" | |
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 singUp(){ | |
Auth.auth().createUser(withEmail: email, password: password) { (result, error) in | |
guard error == nil else { | |
print(error!.localizedDescription) | |
return | |
} | |
print("WE have Signed Up") | |
} | |
} |
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 now = Date() | |
let olderDate = Date(timeIntervalSinceNow: -10000) | |
var order = Calendar.current.compare(now, to: olderDate, toGranularity: .day) | |
switch order { | |
case .orderedDescending: | |
print("DESCENDING") | |
case .orderedAscending: |
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 todaysTimeStamp = 1621429320 | |
var today : Date = Date(timeIntervalSince1970: todaysTimeStamp ) |
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 isValidEmail(_ email: String) -> Bool { | |
let emailCode = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}" | |
let emailPredicate = NSPredicate(format:"SELF MATCHES %@", emailCode) | |
return emailPredicate.evaluate(with: email) | |
} |
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 pass = NSPredicate(format: "SELF MATCHES %@ ", "^(?=.*[a-z])(?=.*[$@$#!%*?&])(?=.*[A-Z]).{6,}$") | |
pass.evaluate(with: "SomStrin&&") // true | |
pass.evaluate(with: "nononnsdf") // false |