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
// | |
// SwiftUITimer.swift | |
// | |
// | |
// Created by Hai Kieu on 7/13/23. | |
// https://medium.com/@programmingpassion/best-solution-to-enhance-timer-in-swiftui-501096572139 | |
import SwiftUI | |
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
var thePixelBuffer : CVPixelBuffer? | |
let testImage : UIImage = UIImage.init(named: "twdEnds.png")! | |
self.thePixelBuffer = self.pixelBufferFromImage(image: testImage) | |
func pixelBufferFromImage(image: UIImage) -> CVPixelBuffer { | |
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 search(pattern: String, input text: String) -> [NSTextCheckingResult] { | |
guard let regex = try? NSRegularExpression.init(pattern: pattern, options: .caseInsensitive) else { | |
return [] | |
} | |
return regex.matches(in: text, options: [], range: NSRange.init(location: 0, length: text.count)) | |
} | |
func searchStrings(pattern: String, input text: String) -> [String] { |
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 UIImage { | |
func resize(size: CGSize) -> UIImage? { | |
guard let cgImage = self.cgImage else { return nil} | |
var format = vImage_CGImageFormat(bitsPerComponent: 8, bitsPerPixel: 32, colorSpace: nil, | |
bitmapInfo: CGBitmapInfo(rawValue: CGImageAlphaInfo.first.rawValue), | |
version: 0, decode: nil, renderingIntent: CGColorRenderingIntent.defaultIntent) | |
var sourceBuffer = vImage_Buffer() |
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 Student { | |
var name: String | |
var age: Int | |
init(_ name: String, age: Int) { | |
print("Hello student \(name)") |
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 authenticateUser(_ username: String?, with password: String?) -> Bool { | |
guard let username = username, let password = password else { | |
//Bad input, do something and return | |
... | |
return false | |
} | |
//Golden path, everything goes well so far | |
let found = lookupDatabase(username, password) | |
return found |
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 authenticateUser(_ username: String?, with password: String?) -> Bool { | |
if let username = username, let password = password { | |
//Validate usernane and password | |
... | |
return true //Assuming, the username and password are valid | |
} else { | |
//Base input, do something | |
return false | |
} | |
} |
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 optionalString : String? | |
guard let theString = optionalString else { | |
return | |
} | |
//do something with theString |
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 UIImage { | |
///UIImage instance somtimes can be at any various orientation, so this method basically converts it back to default orientation. | |
///This is picked from the original source -> https://gist.github.com/schickling/b5d86cb070130f80bb40 | |
func fixedOrientation() -> UIImage? { | |
guard imageOrientation != UIImageOrientation.up else { | |
//This is correct orientation, don't need to do anything | |
return self.copy() as? UIImage | |
} | |