Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am hashaam on github.
  • I am hashaam (https://keybase.io/hashaam) on keybase.
  • I have a public key whose fingerprint is 9B13 E340 5453 901A CB45 8408 2B0C BF4B F563 75A7

To claim this, I am signing this object:

@hashaam
hashaam / configure-audio-session-for-background-audio-mode.swift
Last active June 14, 2017 20:52
Configure Audio Session for background audio mode (iOS Project)
// https://hashaam.com/2017/06/15/configure-audio-session-for-background-audio-mode-ios-project/
import UIKit
import AVFoundation
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
@hashaam
hashaam / display-now-playing-information-in-command-center.swift
Created June 14, 2017 21:11
Display now playing information in Command Center
// https://hashaam.com/2017/06/15/display-now-playing-information-in-command-center/
import UIKit
import MediaPlayer
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
@hashaam
hashaam / using-uiwindow-presentation-context.swift
Last active August 31, 2017 11:24
Using UIWindow Presentation Context
// https://hashaam.com/2017/08/31/uiwindow-presentation-context/
if let delegate = UIApplication.shared.delegate, let window = delegate.window, let viewController = window?.presentationContext() {
// perform action on viewController
}
@hashaam
hashaam / uiwindow-presentation-context.swift
Last active August 31, 2017 11:26
UIWindow Presentation Context - Get top most presented UIViewController of UIWindow
// https://hashaam.com/2017/08/31/uiwindow-presentation-context/
extension UIWindow {
func presentationContext(context: UIViewController? = nil) -> UIViewController? {
var presentationContextViewController = rootViewController
if let context = context {
presentationContextViewController = context
}
@hashaam
hashaam / custom-sorting-an-array-in-swift.swift
Last active August 31, 2017 11:27
Custom Sorting an Array in Swift
// https://hashaam.com/2017/07/20/custom-sorting-an-array-in-swift/
struct Business {
let businessId: Int
let rating: Int
}
func sortBusinesses(_ businesses: [Business]) -> [Business] {
let set = NSOrderedSet(array: businesses)
@hashaam
hashaam / handle-remote-control-commands.swift
Last active August 31, 2017 11:28
Handle Remote Control Commands
// https://hashaam.com/2017/07/19/handle-remote-control-commands/
import UIKit
import MediaPlayer
class ViewController: UIViewController {
var player: AVPlayer?
func setupRemoteCommandCenter(enable: Bool) {
@hashaam
hashaam / calling-get-specific-urlqueryitem-from-urlcomponents.swift
Last active September 2, 2017 09:12
Calling Get Specific URLQueryItem from URLComponents
// https://hashaam.com/2017/09/02/get-specific-urlqueryitem-from-urlcomponents
if let utmTermValue = queryParam(urlString: "http://www.example.com/?utm_source=adsite&utm_campaign=adcampaign&utm_term=adkeyword", param: "utm_term") {
// handle utmTermValue
}
@hashaam
hashaam / get-specific-urlqueryitem-from-urlcomponents.swift
Last active September 2, 2017 09:13
Get Specific URLQueryItem from URLComponents
// https://hashaam.com/2017/09/02/get-specific-urlqueryitem-from-urlcomponents
func queryParam(urlString: String?, param: String) -> String? {
guard let urlString = urlString else { return nil }
guard let urlComponents = URLComponents(string: urlString) else { return nil }
guard let queryItems = urlComponents.queryItems else { return nil }
return queryItems.filter { queryItem in
return queryItem.name == param
}.first?.value
@hashaam
hashaam / adjust-scrollview-content-inset-based-on-keyboard-frame-viewwillappear.swift
Last active September 2, 2017 10:20
Adjust Scroll View Content Inset Based on Keyboard Frame
// https://hashaam.com/2017/09/02/adjust-scroll-view-content-inset-based-on-keyboard-frame
override func viewWillAppear(_ animated: Bool) {
NotificationCenter.default.addObserver(self, selector: #selector(adjustForKeyboardHandler(notification:)), name: NSNotification.Name.UIKeyboardWillChangeFrame, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(adjustForKeyboardHandler(notification:)), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
}