Skip to content

Commit

Permalink
Updated operators
Browse files Browse the repository at this point in the history
  • Loading branch information
WindowsMEMZ committed Apr 13, 2024
1 parent b4d26e8 commit 3e105be
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 2 deletions.
94 changes: 94 additions & 0 deletions Sources/DarockKit/CodeExt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,97 @@ public enum ApiFixType {
case client
case server
}

#if canImport(CoreHaptics)
import CoreHaptics

var globalHapticEngine: CHHapticEngine?

public func PlayHaptic(sharpness: Float, intensity: Float) {
guard CHHapticEngine.capabilitiesForHardware().supportsHaptics else { return }
var events = [CHHapticEvent]()
let intensity = CHHapticEventParameter(parameterID: .hapticIntensity, value: intensity)
let sharpness = CHHapticEventParameter(parameterID: .hapticSharpness, value: sharpness)
let event = CHHapticEvent(eventType: .hapticTransient, parameters: [intensity, sharpness], relativeTime: 0)
events.append(event)
do {
let pattern = try CHHapticPattern(events: events, parameters: [])
let player = try globalHapticEngine?.makePlayer(with: pattern)
try player?.start(atTime: 0)
} catch {
print("Failed to play pattern: \(error.localizedDescription).")
}
}
#endif

postfix operator ++
postfix operator --
prefix operator ++
prefix operator --
public extension Int {
@discardableResult
static postfix func ++ (num: inout Int) -> Int {
num += 1
return num - 1
}

@discardableResult
static postfix func -- (num: inout Int) -> Int {
num -= 1
return num + 1
}

@discardableResult
static prefix func ++ (num: inout Int) -> Int {
num += 1
return num
}

@discardableResult
static prefix func -- (num: inout Int) -> Int {
num -= 1
return num
}
}

public extension Bool {
@_transparent
init(_ input: Int) {
if input == 0 {
self = false
} else {
self = true
}
}
}
public extension Int {
@_transparent
init (_ input: Bool) {
if input {
self = 1
} else {
self = 0
}
}
}

infix operator ~
public extension Float {
static func ~ (lhs: Float, rhs: Int) -> String {
return String(format: "%.\(rhs)f", lhs)
}
}
public extension Double {
static func ~ (lhs: Double, rhs: Int) -> String {
return String(format: "%.\(rhs)f", lhs)
}
}

prefix operator &&
public prefix func && <T>(input: inout T) -> UnsafeMutablePointer<T> {
withUnsafeMutablePointer(to: &input) { $0 }
}
prefix operator *
public prefix func * <T>(ptr: UnsafeMutablePointer<T>) -> T {
return ptr.pointee
}
13 changes: 11 additions & 2 deletions With_Previews.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/Alamofire/Alamofire",
"state" : {
"revision" : "f82c23a8a7ef8dc1a49a8bfc6a96883e79121864",
"version" : "5.5.0"
"revision" : "f455c2975872ccd2d9c81594c658af65716e9b9a",
"version" : "5.9.1"
}
},
{
Expand All @@ -18,6 +18,15 @@
"version" : "5.0.1"
}
},
{
"identity" : "swiftdate",
"kind" : "remoteSourceControl",
"location" : "https://github.com/malcommac/SwiftDate",
"state" : {
"revision" : "5d943224c3bb173e6ecf27295611615eba90c80e",
"version" : "7.0.0"
}
},
{
"identity" : "swiftyjson",
"kind" : "remoteSourceControl",
Expand Down

0 comments on commit 3e105be

Please sign in to comment.