Skip to content

Commit b6178ad

Browse files
author
Eric Wu
committed
增加base64 加密方法
1 parent 2013c2f commit b6178ad

File tree

3 files changed

+117
-100
lines changed

3 files changed

+117
-100
lines changed

CRBoostSwift/Classes/Foundation+CRBoost.swift

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,30 @@ extension String {
7878
return md5Hex
7979
}
8080
@discardableResult
81+
public func base64String() -> String? {
82+
if let data = self.data(using: .utf8) {
83+
return data.base64EncodedString()
84+
}
85+
return nil
86+
}
87+
88+
@discardableResult
89+
public func base64Decoded() -> String? {
90+
if let data = Data(base64Encoded: self) {
91+
return String(data: data, encoding: .utf8)
92+
}
93+
return nil
94+
}
95+
96+
@discardableResult
97+
public func isBase64() -> Bool {
98+
if Data(base64Encoded: self, options: []) != nil {
99+
return true
100+
} else {
101+
return false
102+
}
103+
}
104+
@discardableResult
81105
public func removeDecimalLastZeros () -> String {
82106
var result = self
83107
while result.contains(".") && result.hasSuffix("0") {
@@ -97,14 +121,6 @@ extension String {
97121
let randomString = String(randomCharacters)
98122
return randomString
99123
}
100-
@discardableResult
101-
public func isBase64() -> Bool {
102-
if Data(base64Encoded: self, options: []) != nil {
103-
return true
104-
} else {
105-
return false
106-
}
107-
}
108124

109125
@discardableResult
110126
public func joinUrl(url: String) -> String {
@@ -607,5 +623,5 @@ extension UIColor {
607623
public class func colorWithString(string: String) -> UIColor {
608624
return UIColor()
609625
}
610-
626+
611627
}

Example/CRBoostSwift.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@
168168
607FACCC1AFB9204008FA782 /* Sources */,
169169
607FACCD1AFB9204008FA782 /* Frameworks */,
170170
607FACCE1AFB9204008FA782 /* Resources */,
171-
DCDDAF20841A568EEA724CC3 /* [CP] Embed Pods Frameworks */,
171+
892FE627C106D8CA003BC318 /* [CP] Embed Pods Frameworks */,
172172
);
173173
buildRules = (
174174
);
@@ -303,7 +303,7 @@
303303
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
304304
showEnvVarsInLog = 0;
305305
};
306-
DCDDAF20841A568EEA724CC3 /* [CP] Embed Pods Frameworks */ = {
306+
892FE627C106D8CA003BC318 /* [CP] Embed Pods Frameworks */ = {
307307
isa = PBXShellScriptBuildPhase;
308308
buildActionMask = 2147483647;
309309
files = (

0 commit comments

Comments
 (0)