mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Add asserts around Swift singletons.
This commit is contained in:
parent
7a1e47cd26
commit
36703d3bbd
|
@ -106,6 +106,7 @@
|
||||||
3478506A1FD9B78A007B8332 /* AppSetup.h in Headers */ = {isa = PBXBuildFile; fileRef = 347850661FD9B789007B8332 /* AppSetup.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
3478506A1FD9B78A007B8332 /* AppSetup.h in Headers */ = {isa = PBXBuildFile; fileRef = 347850661FD9B789007B8332 /* AppSetup.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||||
3478506B1FD9B78A007B8332 /* NoopCallMessageHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 347850671FD9B78A007B8332 /* NoopCallMessageHandler.swift */; };
|
3478506B1FD9B78A007B8332 /* NoopCallMessageHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 347850671FD9B78A007B8332 /* NoopCallMessageHandler.swift */; };
|
||||||
3478506C1FD9B78A007B8332 /* NoopNotificationsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 347850681FD9B78A007B8332 /* NoopNotificationsManager.swift */; };
|
3478506C1FD9B78A007B8332 /* NoopNotificationsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 347850681FD9B78A007B8332 /* NoopNotificationsManager.swift */; };
|
||||||
|
347850591FD9972E007B8332 /* SwiftSingletons.swift in Sources */ = {isa = PBXBuildFile; fileRef = 347850581FD9972E007B8332 /* SwiftSingletons.swift */; };
|
||||||
3497DBEC1ECE257500DB2605 /* OWSCountryMetadata.m in Sources */ = {isa = PBXBuildFile; fileRef = 3497DBEB1ECE257500DB2605 /* OWSCountryMetadata.m */; };
|
3497DBEC1ECE257500DB2605 /* OWSCountryMetadata.m in Sources */ = {isa = PBXBuildFile; fileRef = 3497DBEB1ECE257500DB2605 /* OWSCountryMetadata.m */; };
|
||||||
3497DBEF1ECE2E4700DB2605 /* DomainFrontingCountryViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3497DBEE1ECE2E4700DB2605 /* DomainFrontingCountryViewController.m */; };
|
3497DBEF1ECE2E4700DB2605 /* DomainFrontingCountryViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3497DBEE1ECE2E4700DB2605 /* DomainFrontingCountryViewController.m */; };
|
||||||
34B0796D1FCF46B100E248C2 /* MainAppContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 34B0796B1FCF46B000E248C2 /* MainAppContext.m */; };
|
34B0796D1FCF46B100E248C2 /* MainAppContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 34B0796B1FCF46B000E248C2 /* MainAppContext.m */; };
|
||||||
|
@ -572,6 +573,7 @@
|
||||||
347850661FD9B789007B8332 /* AppSetup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppSetup.h; sourceTree = "<group>"; };
|
347850661FD9B789007B8332 /* AppSetup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppSetup.h; sourceTree = "<group>"; };
|
||||||
347850671FD9B78A007B8332 /* NoopCallMessageHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NoopCallMessageHandler.swift; sourceTree = "<group>"; };
|
347850671FD9B78A007B8332 /* NoopCallMessageHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NoopCallMessageHandler.swift; sourceTree = "<group>"; };
|
||||||
347850681FD9B78A007B8332 /* NoopNotificationsManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NoopNotificationsManager.swift; sourceTree = "<group>"; };
|
347850681FD9B78A007B8332 /* NoopNotificationsManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NoopNotificationsManager.swift; sourceTree = "<group>"; };
|
||||||
|
347850581FD9972E007B8332 /* SwiftSingletons.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftSingletons.swift; sourceTree = "<group>"; };
|
||||||
348F2EAD1F0D21BC00D4ECE0 /* DeviceSleepManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DeviceSleepManager.swift; sourceTree = "<group>"; };
|
348F2EAD1F0D21BC00D4ECE0 /* DeviceSleepManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DeviceSleepManager.swift; sourceTree = "<group>"; };
|
||||||
3495BC911F1426B800B478F5 /* ar */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ar; path = translations/ar.lproj/Localizable.strings; sourceTree = "<group>"; };
|
3495BC911F1426B800B478F5 /* ar */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ar; path = translations/ar.lproj/Localizable.strings; sourceTree = "<group>"; };
|
||||||
3497DBEA1ECE257500DB2605 /* OWSCountryMetadata.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSCountryMetadata.h; sourceTree = "<group>"; };
|
3497DBEA1ECE257500DB2605 /* OWSCountryMetadata.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSCountryMetadata.h; sourceTree = "<group>"; };
|
||||||
|
@ -1097,6 +1099,7 @@
|
||||||
346129BE1FD2068600532771 /* ThreadUtil.m */,
|
346129BE1FD2068600532771 /* ThreadUtil.m */,
|
||||||
B97940251832BD2400BD66CB /* UIUtil.h */,
|
B97940251832BD2400BD66CB /* UIUtil.h */,
|
||||||
B97940261832BD2400BD66CB /* UIUtil.m */,
|
B97940261832BD2400BD66CB /* UIUtil.m */,
|
||||||
|
347850581FD9972E007B8332 /* SwiftSingletons.swift */,
|
||||||
346129751FD1E0B500532771 /* WeakTimer.swift */,
|
346129751FD1E0B500532771 /* WeakTimer.swift */,
|
||||||
);
|
);
|
||||||
path = utils;
|
path = utils;
|
||||||
|
@ -2685,6 +2688,7 @@
|
||||||
346129E61FD5C0C600532771 /* OWSDatabaseMigrationRunner.m in Sources */,
|
346129E61FD5C0C600532771 /* OWSDatabaseMigrationRunner.m in Sources */,
|
||||||
346129AB1FD1F0EE00532771 /* OWSFormat.m in Sources */,
|
346129AB1FD1F0EE00532771 /* OWSFormat.m in Sources */,
|
||||||
451F8A461FD715BA005CB9DA /* OWSGroupAvatarBuilder.m in Sources */,
|
451F8A461FD715BA005CB9DA /* OWSGroupAvatarBuilder.m in Sources */,
|
||||||
|
347850591FD9972E007B8332 /* SwiftSingletons.swift in Sources */,
|
||||||
346129961FD1E30000532771 /* OWSDatabaseMigration.m in Sources */,
|
346129961FD1E30000532771 /* OWSDatabaseMigration.m in Sources */,
|
||||||
346129CD1FD2072E00532771 /* UIImage+OWS.m in Sources */,
|
346129CD1FD2072E00532771 /* UIImage+OWS.m in Sources */,
|
||||||
450998661FD8BD9C00D89EB3 /* FullImageViewController.m in Sources */,
|
450998661FD8BD9C00D89EB3 /* FullImageViewController.m in Sources */,
|
||||||
|
|
|
@ -20,30 +20,3 @@ public func owsFail(_ message: String) {
|
||||||
Logger.flush()
|
Logger.flush()
|
||||||
assertionFailure(message)
|
assertionFailure(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SwiftSingletons: NSObject {
|
|
||||||
public static let shared = SwiftSingletons()
|
|
||||||
|
|
||||||
private var classSet = Set<String>()
|
|
||||||
|
|
||||||
private override init() {
|
|
||||||
super.init()
|
|
||||||
}
|
|
||||||
|
|
||||||
public func register(_ singleton: AnyObject) {
|
|
||||||
guard _isDebugAssertConfiguration() else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
let singletonClassName = String(describing:type(of:singleton))
|
|
||||||
guard !classSet.contains(singletonClassName) else {
|
|
||||||
owsFail("\(self.logTag()) in \(#function) Duplicate singleton: \(singletonClassName).")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
Logger.verbose("\(self.logTag()) in \(#function) Registering singleton: \(singletonClassName).")
|
|
||||||
classSet.insert(singletonClassName)
|
|
||||||
}
|
|
||||||
|
|
||||||
public static func register(_ singleton: AnyObject) {
|
|
||||||
shared.register(singleton)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
32
SignalMessaging/utils/SwiftSingletons.swift
Normal file
32
SignalMessaging/utils/SwiftSingletons.swift
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
//
|
||||||
|
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
public class SwiftSingletons: NSObject {
|
||||||
|
public static let shared = SwiftSingletons()
|
||||||
|
|
||||||
|
private var classSet = Set<String>()
|
||||||
|
|
||||||
|
private override init() {
|
||||||
|
super.init()
|
||||||
|
}
|
||||||
|
|
||||||
|
public func register(_ singleton: AnyObject) {
|
||||||
|
guard _isDebugAssertConfiguration() else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let singletonClassName = String(describing:type(of:singleton))
|
||||||
|
guard !classSet.contains(singletonClassName) else {
|
||||||
|
owsFail("\(self.logTag()) in \(#function) Duplicate singleton: \(singletonClassName).")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
Logger.verbose("\(self.logTag()) in \(#function) Registering singleton: \(singletonClassName).")
|
||||||
|
classSet.insert(singletonClassName)
|
||||||
|
}
|
||||||
|
|
||||||
|
public static func register(_ singleton: AnyObject) {
|
||||||
|
shared.register(singleton)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue