Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions Sources/SCFNotification/SCFNotificationCenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ public class SCFNotificationCenter {
userInfo: userInfo,
deliverImmediately: deliverImmediately)
}

public func postNotification(name: CFNotificationName,
object: AnyObject? = nil,
userInfo: CFDictionary,
options: Set<Option>) {
Self.postNotification(center: center,
name: name,
object: object,
userInfo: userInfo,
options: options)
}
}


Expand Down Expand Up @@ -131,6 +142,23 @@ extension SCFNotificationCenter {

CFNotificationCenterPostNotification(center.cfNotificationCenter, name, objectPtr, userInfo, deliverImmediately)
}

public static func postNotification(center: CenterType,
name: CFNotificationName,
object: AnyObject? = nil,
userInfo: CFDictionary,
options: Set<Option>) {
var objectPtr: UnsafeRawPointer?
if let object {
objectPtr = unsafeBitCast(object, to: UnsafeRawPointer.self)
}

let options: CFOptionFlags = options.reduce(into: 0) { partialResult, option in
partialResult = partialResult | option.flag
}

CFNotificationCenterPostNotificationWithOptions(center.cfNotificationCenter, name, objectPtr, userInfo, options)
}
}

extension SCFNotificationCenter {
Expand All @@ -155,3 +183,17 @@ extension SCFNotificationCenter {
}
}
}

extension SCFNotificationCenter {
public enum Option: CaseIterable {
case deliverImmediately
case postToAllSessions

var flag: CFOptionFlags {
switch self {
case .deliverImmediately: return kCFNotificationDeliverImmediately
case .postToAllSessions: return kCFNotificationPostToAllSessions
}
}
}
}