Skip to content

Commit 33c9874

Browse files
committed
macos fixes, warning fixes
1 parent dc28995 commit 33c9874

File tree

5 files changed

+54
-21
lines changed

5 files changed

+54
-21
lines changed

Sources/SwiftFortuneWheel/Utils/Animation/SpinningWheelAnimator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import UIKit
1616
#endif
1717

1818
/// Spinning animator protocol
19-
protocol SpinningAnimatorProtocol: class, CollisionProtocol {
19+
protocol SpinningAnimatorProtocol: AnyObject, CollisionProtocol {
2020
/// Layer that animates
2121
var layerToAnimate: SpinningAnimatable? { get }
2222
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//
2+
// AudioPersistencing.swift
3+
// SwiftFortuneWheel
4+
//
5+
// Created by Sherzod Khashimov on 27/10/22.
6+
// Copyright © 2022 SwiftFortuneWheel. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import AVFoundation
11+
12+
protocol AudioPersistencing {
13+
func enableHandleInterruption()
14+
}
15+
16+
extension AudioPersistencing {
17+
#if canImport(AVAudioSession)
18+
func enableHandleInterruption() {
19+
NotificationCenter.default.addObserver(self,
20+
selector: #selector(handleInterruption),
21+
name: AVAudioSession.interruptionNotification,
22+
object: AVAudioSession.sharedInstance())
23+
}
24+
25+
/// Stops audio when interrupted
26+
@objc func handleInterruption(notification: Notification) {
27+
guard let userInfo = notification.userInfo,
28+
let typeValue = userInfo[AVAudioSessionInterruptionTypeKey] as? UInt,
29+
let type = AVAudioSession.InterruptionType(rawValue: typeValue) else {
30+
return
31+
}
32+
33+
isAudioInterrupted = type == .began
34+
35+
if isAudioInterrupted {
36+
node.stop()
37+
}
38+
}
39+
#else
40+
func enableHandleInterruption() {
41+
//do nothing
42+
}
43+
#endif
44+
}

Sources/SwiftFortuneWheel/Utils/Audio/AudioPlayer.swift

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,7 @@ class AudioPlayer {
1717
private(set) var isAudioInterrupted = false
1818

1919
init() {
20-
NotificationCenter.default.addObserver(self,
21-
selector: #selector(handleInterruption),
22-
name: AVAudioSession.interruptionNotification,
23-
object: AVAudioSession.sharedInstance())
24-
}
25-
26-
/// Stops audio when interrupted
27-
@objc private func handleInterruption(notification: Notification) {
28-
guard let userInfo = notification.userInfo,
29-
let typeValue = userInfo[AVAudioSessionInterruptionTypeKey] as? UInt,
30-
let type = AVAudioSession.InterruptionType(rawValue: typeValue) else {
31-
return
32-
}
33-
34-
isAudioInterrupted = type == .began
35-
36-
if isAudioInterrupted {
37-
node.stop()
38-
}
20+
enableHandleInterruption()
3921
}
4022

4123
/// Plays `AVAudioFile` for sound identifier
@@ -68,6 +50,9 @@ class AudioPlayer {
6850
}
6951
}
7052

53+
// Enables handle interruption implementation
54+
extension AudioPlayer: AudioPersistencing {}
55+
7156
extension AudioPlayer {
7257
/// Audio player's status type
7358
enum Status {

Sources/SwiftFortuneWheel/Utils/Calculating/WheelMathCalculating.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import UIKit
1515
#endif
1616

1717
/// Wheel other math calculation protocol
18-
protocol WheelMathCalculating: class {
18+
protocol WheelMathCalculating: AnyObject {
1919

2020
/// Wheel frame
2121
var frame: CGRect { get set }

SwiftFortuneWheel.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
277FCC7B251DC89700CC6590 /* CALayer+UpdateValues.swift in Sources */ = {isa = PBXBuildFile; fileRef = 277FCC7A251DC89700CC6590 /* CALayer+UpdateValues.swift */; };
5353
2787E56E24A728F900533AD4 /* String+Width.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2787E56D24A728F900533AD4 /* String+Width.swift */; };
5454
2787E57024A7292F00533AD4 /* String+Lines.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2787E56F24A7292F00533AD4 /* String+Lines.swift */; };
55+
2789BDF2290B294000B7F535 /* AudioPersistencing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2789BDF1290B294000B7F535 /* AudioPersistencing.swift */; };
5556
27A5741E253EB46300B060FF /* AudioPlayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27A5741D253EB46300B060FF /* AudioPlayer.swift */; };
5657
27A57422253EB46D00B060FF /* AudioPlayerManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27A57421253EB46D00B060FF /* AudioPlayerManager.swift */; };
5758
27A57426253EB57900B060FF /* AudioError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27A57425253EB57900B060FF /* AudioError.swift */; };
@@ -125,6 +126,7 @@
125126
277FCC7A251DC89700CC6590 /* CALayer+UpdateValues.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CALayer+UpdateValues.swift"; sourceTree = "<group>"; };
126127
2787E56D24A728F900533AD4 /* String+Width.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Width.swift"; sourceTree = "<group>"; };
127128
2787E56F24A7292F00533AD4 /* String+Lines.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Lines.swift"; sourceTree = "<group>"; };
129+
2789BDF1290B294000B7F535 /* AudioPersistencing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioPersistencing.swift; sourceTree = "<group>"; };
128130
27A5741D253EB46300B060FF /* AudioPlayer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioPlayer.swift; sourceTree = "<group>"; };
129131
27A57421253EB46D00B060FF /* AudioPlayerManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioPlayerManager.swift; sourceTree = "<group>"; };
130132
27A57425253EB57900B060FF /* AudioError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioError.swift; sourceTree = "<group>"; };
@@ -359,6 +361,7 @@
359361
27A57421253EB46D00B060FF /* AudioPlayerManager.swift */,
360362
27E291BF2550300800486B6D /* AudioPlayable.swift */,
361363
27E291C32550309200486B6D /* ImpactFeedbackable.swift */,
364+
2789BDF1290B294000B7F535 /* AudioPersistencing.swift */,
362365
);
363366
path = Audio;
364367
sourceTree = "<group>";
@@ -587,6 +590,7 @@
587590
27105670248D4C93006C0181 /* TextPreferences.swift in Sources */,
588591
277BB2B2253B3AB5007E7E93 /* CollisionDetector.swift in Sources */,
589592
2725A0342549386C00C6F7CF /* CollisionType.swift in Sources */,
593+
2789BDF2290B294000B7F535 /* AudioPersistencing.swift in Sources */,
590594
2710F81B254ABA3900033887 /* CollisionDetectable.swift in Sources */,
591595
2703B4F4248E204E00FB50F9 /* SFWConfiguration.swift in Sources */,
592596
277D66B126787F0E00AB1FAA /* SFGradientColor.swift in Sources */,

0 commit comments

Comments
 (0)