Skip to content

Instantly share code, notes, and snippets.

View fredriccliver's full-sized avatar
🧭
To the north

Fredric Cliver fredriccliver

🧭
To the north
View GitHub Profile
func commentButtonSlideIn(fromRight:Bool = true){
if(fromRight){
myButton.trailingAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.trailingAnchor, constant: 15).isActive = true
myButton.frame.origin.x = UIScreen.main.bounds.width
}else{
myButton.leadingAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.leadingAnchor, constant: -15).isActive = true
myButton.frame.origin.x = -80
}
import Foundation
extension String {
var withoutPunctuations: String {
return self.components(separatedBy: CharacterSet.punctuationCharacters).joined(separator: "")
}
}
let originalStr:String = "hello, (Nice to- meet 한국 école %&$you all. 123 ! Давай العربية 😀"
extension UIViewController {
func resizeHeaderView(tableView:UITableView) {
guard let headerView = tableView.tableHeaderView else {
return
}
headerView.setNeedsLayout()
headerView.layoutIfNeeded()
tableView.sectionHeaderHeight = UITableView.automaticDimension
asyncfunction(){ result in
async2func(){ result in
async3func() { result in
//...
}
}
}
let asyncQueue = DispatchGroup()
for person in people{
asyncQueue.enter()
// "checkIdentity" is a Async function which takes networking resource and consume a bit of time.
self.checkIdentity(person) { (err) in
if(err != nil){
func logg(_ object: Any, filepath:String = #file, functionname:String = #function, linenumber:Int = #line){
#if DEBUG
let filename = (filepath as NSString).lastPathComponent
print("🔨", filename,">", functionname,">", linenumber)
print(object)
// 🔨 ViewController.swift > myFunction(param:) > 36
#endif
}
import Foundation
import Firebase
import FirebaseFunctions
import FirebaseFirestoreSwift
struct MyCollection: Codable {
var _id:String?
var title:String
var description:String?
var keywords:[String]?
@IBAction func onSave(_ sender: UIBarButtonItem) {
if(self.sentence == nil){
print("Insufficient Sentence Data")
addSoundButton.shake()
return
}
}
extension UIView{
// ...
func shake(){
let animation = CAKeyframeAnimation(keyPath: "transform.translation.x")
animation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.linear)
animation.duration = 0.6
animation.values = [-20.0, 20.0, -20.0, 20.0, -10.0, 10.0, -5.0, 5.0, 0.0 ]
self.layer.add(animation, forKey: "shake")
let functions = Functions.functions()
functions.useFunctionsEmulator(origin: "http://localhost:5001")
functions.httpsCallable("generateSound").call() { (result, error) in
if let error = error as NSError? {
if error.domain == FunctionsErrorDomain {
let code = FunctionsErrorCode(rawValue: error.code)
let message = error.localizedDescription
let details = error.userInfo[FunctionsErrorDetailsKey]
print(code ?? "", message , details ?? "")