Skip to content

Repository files navigation

DDUtils

DDUtils is a collection of commonly used features, developed based on Swift, that can be quickly implemented on iOS devices.

import the project

Import via cocoapods

pod 'DDUtils'

If you need the function of idfa, you can choose to import

pod 'DDUtils/idfa'

Import via file

Download the project and import the contents of the pod folder under the project file into the project

API list

Existing data type operations can be used through the syntax of .zx, and other operations can be used through the singleton of DDUtils.shared.

  • There is no difference between singleton and .zx, singleton will be more unified and simple. The advantage of .zx syntax is that it does not need to be imported where it is used

UI related

NameFunction descriptionExample
func getCurrentNormalWindow()Get the current NormalWindowDDUtils.shared.getCurrentNormalWindow()
func getCurrentVC()Get the current ViewControllerDDUtils.shared.getCurrentVC()
func getImage(color: UIColor)Generate a solid color background image by colorDDUtils.shared.getImage(color: UIColor.red)
or
UIImage.dd.getImage(color: UIColor .red)
func getLinearGradientImage(colors: [UIColor], directionType: DDUtilsGradientDirection, size: CGSize = CGSize(width: 100, height: 100))Generate a linear gradient imageDDUtils.shared.getLinearGradientImage(colors: [UIColor.red , UIColor.black, UIColor.blue]
or
UIImage.dd.getLinearGradientImage(colors: [UIColor.red, UIColor.black, UIColor.blue], directionType: .leftToRight)
func getRadialGradientImage(colors: [UIColor], raduis: CGFloat, size: CGSize = CGSize(width: 100, height: 100))Generate an angular gradient imageDDUtils.shared.getRadialGradientImage(colors: [UIColor.red , UIColor.black, UIColor.blue], raduis: 45)
or
UIImage.dd.getRadialGradientImage(colors: [UIColor.red, UIColor.black, UIColor.blue], raduis: 45)
func getColor(hexString: String, alpha: CGFloat = 1.0)Get color by hexadecimal stringUIColor.dd.color(hexString: "#FFFFFF")
func UIColor(hexValue: Int, darkHexValue: Int = 0x333333, alpha: Float = 1.0, darkAlpha: Float = 1.0)Get color by hexadecimalUIColor.dd.color(hexValue: 0xffffff)
UIScreenWidthScreen width
UIScreenHeightScreen height
DDUtils_StatusBar_HeightStatus Bar height
DDUtils_HomeIndicator_HeightHome Indicator height
func DDUtils_Default_NavigationBar_Height(vc: UIViewController? = nil)Navigation Bar HeightDDUtils_Default_NavigationBar_Height()
func func DDUtils_Default_Tabbar_Height(vc: UIViewController? = nil)tabbar heightDDUtils_Default_Tabbar_Height()
func addLayerShadow(color: UIColor, offset: CGSize, radius: CGFloat, cornerRadius: CGFloat? = nil)Add a shadow to the viewview.dd.addLayerShadow(color: UIColor.black, offset: CGSize(width: 2, height : 0), radius: 10)
func setFrame(x: CGFloat? = nil, y: CGFloat? = nil, width: CGFloat? = nil, height: CGFloat? = nil)view individually sets a certain value of Frameview.dd.setFrame(x: 10)
func className() -> Stringget view's class namebutton.dd.className()

System and software information

NameFunction descriptionExample
func getAppVersionString()Get software versionDDUtils.shared.getAppVersionString()
func getAppBuildVersionString()Get software build versionDDUtils.shared.getAppBuildVersionString()
func getAppNameString()get app's NameDDUtils.shared.getAppNameString()
func getIOSVersionString()Get the iOS version of the systemDDUtils.shared.getIOSVersionString()
func getIOSLanguageStr()Get system languageDDUtils.shared.getIOSLanguageStr()
func getBundleIdentifier()Get Software Bundle IdentifierDDUtils.shared.getBundleIdentifier()
func getSystemHardware()Get the machine model identificationDDUtils.shared.getSystemHardware()
func getSystemUpTime()Get the last restart time of this machineDDUtils.shared.getSystemUpTime()
func getIDFAString(idfvIfFailed: Bool = true)The unique identification of the simulation softwareDDUtils.shared.getIDFAString()
func getMacAddress()To get the MAC address of the mobile phone WIFI, you need to enable Access WiFi informationDDUtils.shared.getMacAddress()
func openSystemSetting()Open system settingsDDUtils.shared.openSystemSetting()
func openAppStorePage(openType: DDUtilsOpenAppStoreType, appleID: String)Open the App Store page corresponding to the softwareDDUtils.shared.openAppStorePage(openType: .app, appleID: "1123211")
func openAppStoreReviewPage(openType: DDUtilsOpenAppStoreType, appleID: String = "")Open the score page corresponding to the softwareDDUtils.shared.openAppStoreReviewPage(openType: .app)

Software permissions

NameFunction descriptionExample
func requestPermission(type: DDUtilsPermissionType, complete: @escaping ((DDUtilsPermissionStatus) -> Void))Request permissionDDUtils.shared.requestPermission(type: .notification) {(status) in print("Permission setting callback" , status) }
func checkPermission(type: DDUtilsPermissionType, complete: @escaping ((DDUtilsPermissionStatus) -> Void))Checking software permissionsDDUtils.shared.checkPermission(type: .notification) {(status) in print("Current permission status ", status) }
func requestIDFAPermission(complete: @escaping ((DDUtilsPermissionStatus) -> Void)) -> Voidrequest idfa permissionDDUtils.shared.requestIDFAPermission {(status) in print("Current idfa permission status", status)}
func checkIDFAPermission(type: DDUtilsPermissionType, complete: @escaping ((DDUtilsPermissionStatus) -> Void)) -> Voidcheck software idfa permissionDDUtils.shared.checkIDFAPermission {(status) in print("Current Permission Status", status) }

Multimedia operation

NameFunction descriptionExample
func getVideoDuration(videoURL: URL) -> DoubleGet the duration of the specified video, in secondsDDUtils.shared.getVideoDuration(videoURL: URL(fileURLWithPath: path))
func getVideoSize(videoURL: URL)Get the specified video resolution, support local or network addressDDUtils.shared.getVideoSize(videoURL: URL(fileURLWithPath: path))
func playMusic(url: URL?, repeated: Bool = false, audioSessionCategory: AVAudioSession.Category = AVAudioSession.Category.playback)Play musicDDUtils.shared.playMusic(url: url, repeated: false)
func stopMusic()Turn off music playbackDDUtils.shared.stopMusic()
func playEffect(url: URL?, vibrate: Bool = false)Play sound effects, silent mode will not play sound effectsDDUtils.shared.playEffect(url: url, vibrate: true)
func startVibrate(repeated: Bool = false)Start vibrationDDUtils.shared.startVibrate()
func stopVibrate()End vibrationDDUtils.shared.stopVibrate()

File operations

NameFunction descriptionExample
func getFileDirectory(type: DDUtilsFileDirectoryType)Get folder pathDDUtils.shared.getFileDirectory(type: .documents)
func createFileDirectory(in type: DDUtilsFileDirectoryType, directoryName: String)Create a folder in the specified folderDDUtils.shared.createFileDirectory(in: .documents, directoryName: "filePath")
func getFileSize(filePath: URL)Get the size of the specified fileDDUtils.shared.getFileSize(filePath: url)
func getFileDirectorySize(fileDirectoryPth: URL)Get the size of the specified folderDDUtils.shared.getFileDirectorySize(fileDirectoryPth: url)

Other

DDUtils

NameFunction descriptionExample
func getDictionary(object: Any, debug: Bool = false) -> [String: Any]get all key and value from class\structDDUtils.shared.getDictionary(object: testModel)
func runInMainThread(type: ZXMainThreadType = .default, function: @escaping ()->Void)run function in main threadDDUtils.shared.runInMainThread(type: .sync) { ... }

String

NameFunction descriptionExample
func subString(rang: NSRange)截取字符串string.dd.subString(rang: NSRange(location: 2, length: 5))
func unicodeDecode()unicode转中文"\u54c8\u54c8\u54c8".dd.unicodeDecode()
func unicodeEncode()字符串转unicode"哈哈是电话费".dd.unicodeEncode()
func encodeString(from originType: DDUtilsEncodeType = .system(.utf8), to encodeType: DDUtilsEncodeType)字符串修改编码显示"5ZOI5ZOI5piv55S16K+d6LS5".dd.encodeString(from: .base64, to: .system(.utf8))
func aesCBCEncrypt(password: String, ivString: String = "abcdefghijklmnop")aes cbc Encryptstring.dd.aesCBCEncrypt(password: "password")
func aesCBCDecrypt(password: String, ivString: String = "abcdefghijklmnop")aes cbc Decryptstring.dd.aesCBCDecrypt(password: "password")
func hashString(hashType: DDUtilsHashType, lowercase: Bool = true)get hash value of the stringstring.dd.hashString(hashType: .md5)
Support md5/sha1/sha224/sha256/sha384/sha512
func aesGCMEncrypt(password: String, encodeType: DDUtilsEncodeType = .base64, nonce: AES.GCM.Nonce? = AES.GCM.Nonce())aes gcm Encryptstring.dd.aesGCMEncrypt(password: "password")
func aesGCMDecrypt(password: String, encodeType: DDUtilsEncodeType = .base64)aes gcm Decryptstring.dd.aesGCMDecrypt(password: "password")
func hmac(hashType: DDUtilsHashType, password: String, encodeType: DDUtilsEncodeType = .base64)HMAC"DDUtils".dd.hmac(hashType: .sha1, password: "67FG", encodeType: .hex)

Data

NameFunction descriptionExample
static func data(from string: String, encodeType: DDUtilsEncodeType)get data from string with encodeTypeData.dd.data(from: "d5a423f64b607ea7c65b311d855dc48f36114b227bd0c7a3d403f6158a9e4412", encodeType: .hex)
func encodeString(encodeType: DDUtilsEncodeType)encode data to string with encodeTypedata.dd.encodeString(encodeType: .hex)
func aesCBCEncrypt(password: String, ivString: String = "abcdefghijklmnop")aes cbc Encryptdata.dd.aesCBCEncrypt(password: "password")
func aesCBCDecrypt(password: String, ivString: String = "abcdefghijklmnop")aes cbc Decryptdata.dd.aesCBCDecrypt(password: "password")
func hashString(hashType: DDUtilsHashType, lowercase: Bool = true)get hash value of the stringdata.dd. hashString(hashType: .md5)
支持md5/sha1/sha224/sha256/sha384/sha512
func aesGCMEncrypt(password: String, encodeType: DDUtilsEncodeType = .base64, nonce: AES.GCM.Nonce? = AES.GCM.Nonce())aes gcm Encryptdata.dd.aesGCMEncrypt(password: "password")
func aesGCMDecrypt(password: String, encodeType: DDUtilsEncodeType = .base64)aes gcm Decryptdata.dd.aesGCMDecrypt(password: "password")
func hmac(hashType: DDUtilsHashType, password: String, encodeType: DDUtilsEncodeType = .base64)HMACdata.dd.hmac(hashType: .sha1, password: "67FG", encodeType: .hex)

License

The project is based on the MIT License

About

DDUtils is a collection of commonly used features, developed based on Swift, that can be quickly implemented on iOS devices.

Topics

Resources

Stars

7 stars

Watchers

1 watching

Forks

Releases

Contributors

Languages