Skip to content
This repository has been archived by the owner on Oct 4, 2023. It is now read-only.

Upgrade to Swift 3.0 #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
15 changes: 15 additions & 0 deletions Hermes.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,17 @@
TargetAttributes = {
40B186151B20C88100636EEE = {
CreatedOnToolsVersion = 6.3.2;
DevelopmentTeam = U7299KCYL8;
LastSwiftMigration = 0800;
ProvisioningStyle = Automatic;
};
40B186201B20C88100636EEE = {
CreatedOnToolsVersion = 6.3.2;
LastSwiftMigration = 0800;
};
40B186351B20C88E00636EEE = {
CreatedOnToolsVersion = 6.3.2;
LastSwiftMigration = 0800;
};
};
};
Expand Down Expand Up @@ -502,7 +507,9 @@
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = U7299KCYL8;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
Expand All @@ -517,6 +524,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -525,7 +533,9 @@
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = U7299KCYL8;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
Expand All @@ -539,6 +549,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.imgur.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand All @@ -557,6 +568,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.imgur.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -571,6 +583,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.imgur.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand All @@ -588,6 +601,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.imgur.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = HermesApp;
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 1;
};
name = Debug;
Expand All @@ -602,6 +616,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.imgur.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = HermesApp;
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 1;
};
name = Release;
Expand Down
104 changes: 52 additions & 52 deletions Hermes/Hermes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import AVFoundation
:param: notification the notification being made
:returns: the notification view, or nil to use HermesDefaultNotificationView
*/
optional func hermesNotificationViewForNotification(hermes hermes: Hermes, notification: HermesNotification) -> HermesNotificationView?
@objc optional func hermesNotificationViewForNotification(hermes: Hermes, notification: HermesNotification) -> HermesNotificationView?

/**
:param: hermes the Hermes instance
:param: explicit is true if the user closed the bulletin with their finger, instead of relying on autoclose
:param: notification the notification that was showing when Hermes was closed
*/
optional func hermesDidClose(hermes: Hermes, explicit: Bool, notification: HermesNotification)
@objc optional func hermesDidClose(_ hermes: Hermes, explicit: Bool, notification: HermesNotification)
}

/**
Expand All @@ -33,135 +33,135 @@ bugs and still needs to be handled.
*/

@objc public enum HermesStyle : Int {
case Dark, Light
case dark, light
}

public class Hermes: NSObject, HermesBulletinViewDelegate {
open class Hermes: NSObject, HermesBulletinViewDelegate {
// MARK: - Public variables
// MARK: - Singleton
/**
You typically will never need to use more than one instance of Hermes
*/
public static let sharedInstance = Hermes()
public var style: HermesStyle = .Dark
open static let sharedInstance = Hermes()
open var style: HermesStyle = .dark

// MARK: -
weak public var delegate: HermesDelegate?
weak open var delegate: HermesDelegate?

// MARK: - private variables
private var bulletinView: HermesBulletinView?
private var notifications = [HermesNotification]()
fileprivate var bulletinView: HermesBulletinView?
fileprivate var notifications = [HermesNotification]()

var audioPlayer: AVAudioPlayer?

/**
When Hermes is waiting, he will collect all of your notifications. Use wait() and go() to tell Hermes when to collect and when to deliver notifications
*/
private var waiting = false {
fileprivate var waiting = false {
didSet {
if !waiting {
showNotifications()
showNotifications()
}
}
}

// MARK: - Public methods

/**
Give Hermes one notification to post. If waiting == false, you'll see this notification right away

:param: notification The notification you want Hermes to post
*/
public func postNotification(notification: HermesNotification) {
open func postNotification(_ notification: HermesNotification) {
postNotifications([notification])
}

/**
Give Hermes an array of notifications to post. If waiting == false, you'll see these notifications right away

:param: notifications The notifications you want Hermes to post
*/
public func postNotifications(notifications: [HermesNotification]) {
open func postNotifications(_ notifications: [HermesNotification]) {
self.notifications += notifications

if let firstNotification = self.notifications.first {
if firstNotification.soundPath != nil {
prepareSound(path: firstNotification.soundPath!)
}
}

showNotifications()
}

/**
Tell Hermes to wait and you can queue up multiple notifications
*/
public func wait() {
open func wait() {
waiting = true
}

/**
Done queuing up those notifications? Tell Hermes to go!
*/
public func go() {
open func go() {
waiting = false
showNotifications()
}
public func close() {

open func close() {
bulletinView?.close(explicit: false)
}
public func containsNotification(notification: HermesNotification) -> Bool{

open func containsNotification(_ notification: HermesNotification) -> Bool{
if let bulletinView = self.bulletinView {
return bulletinView.notifications.contains(notification)
}
return false
}

// MARK: - private methods

/**
This method will attempt to show all currently queued up notifications. If Hermes has waiting set to true,
This method will attempt to show all currently queued up notifications. If Hermes has waiting set to true,
or if there are not notifications, this method will do nothing
*/
private func showNotifications() {
fileprivate func showNotifications() {
if waiting || notifications.count == 0 || bulletinView != nil {
return
}

bulletinView = HermesBulletinView()

switch style {
case .Dark:
bulletinView!.style = .Dark
case .Light:
bulletinView!.style = .Light
case .dark:
bulletinView!.style = .dark
case .light:
bulletinView!.style = .light
}
bulletinView!.delegate = self
bulletinView!.notifications = notifications
bulletinView!.show()
audioPlayer?.play()
notifications.removeAll(keepCapacity: true)

notifications.removeAll(keepingCapacity: true)
}

// Initial setup
func prepareSound(path path: String) {
let sound = NSURL(fileURLWithPath: path)
audioPlayer = try! AVAudioPlayer(contentsOfURL: sound)
func prepareSound(path: String) {
let sound = URL(fileURLWithPath: path)
audioPlayer = try? AVAudioPlayer(contentsOf: sound)
audioPlayer!.prepareToPlay()
}

// MARK: - HermesBulletinViewDelegate
func bulletinViewDidClose(bulletinView: HermesBulletinView, explicit: Bool) {

func bulletinViewDidClose(_ bulletinView: HermesBulletinView, explicit: Bool) {
delegate?.hermesDidClose?(self, explicit: explicit, notification: bulletinView.currentNotification)
self.bulletinView = nil
showNotifications()
}
func bulletinViewNotificationViewForNotification(notification: HermesNotification) -> HermesNotificationView? {

func bulletinViewNotificationViewForNotification(_ notification: HermesNotification) -> HermesNotificationView? {
return delegate?.hermesNotificationViewForNotification?(hermes: self, notification: notification)
}
}
Loading