Skip to content

Instantly share code, notes, and snippets.

View stevenojo's full-sized avatar

Steven Ojo stevenojo

View GitHub Profile
@stevenojo
stevenojo / jsonString method for Dictionary
Created January 29, 2018 20:21
Convert Dictionary to a JSON string in swift
extension Dictionary {
func jsonString() -> NSString? {
let jsonData = try? JSONSerialization.data(withJSONObject: self, options: [])
guard jsonData != nil else {return nil}
let jsonString = String(data: jsonData!, encoding: .utf8)
guard jsonString != nil else {return nil}
return jsonString! as NSString
}
}
@stevenojo
stevenojo / jsonString method for Dictionary
Created January 29, 2018 20:21
Convert Dictionary to a JSON string in swift
extension Dictionary {
func jsonString() -> NSString? {
let jsonData = try? JSONSerialization.data(withJSONObject: self, options: [])
guard jsonData != nil else {return nil}
let jsonString = String(data: jsonData!, encoding: .utf8)
guard jsonString != nil else {return nil}
return jsonString! as NSString
}
}
@stevenojo
stevenojo / ObjectiveCDebounce.md
Last active May 6, 2023 23:56
Objective-C Debounce Example Using GCD Dispatch Sources / Timer

##Debouncing using GCD on iOS

The idea of "Debouncing" is to limit the rate a function or task can execute by waiting a certain amount of time before executing it. In the example below, if a user rapidly enters input, it will only execute once, 1 second after all that input. This is the implementation of a sample class showing how to do so, while using Grand Central Dispatch to create a timer. The timer fires on a global queue in this example - but you can change the queue to any queue where you want the timer to execute, regardless of where you set it up.

#import <Foundation/Foundation.h>

@interface DebounceExample : NSObject