Browse Source

【OCToSwift】NSString_SKExtensions(项目使用到的已完成)

tangchao 1 year ago
parent
commit
c10fc6888f

+ 8 - 2
PDF Office/PDF Master.xcodeproj/project.pbxproj

@@ -292,7 +292,6 @@
 		89E4E746296418ED002DBA6F /* TextFieldFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = 89E4E745296418ED002DBA6F /* TextFieldFormatter.m */; };
 		89E4E747296418ED002DBA6F /* TextFieldFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = 89E4E745296418ED002DBA6F /* TextFieldFormatter.m */; };
 		89E4E748296418ED002DBA6F /* TextFieldFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = 89E4E745296418ED002DBA6F /* TextFieldFormatter.m */; };
-		89E4E74B2964216F002DBA6F /* NSString_SKExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 89E4E74A2964216F002DBA6F /* NSString_SKExtensions.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
 		89E4E74C2964216F002DBA6F /* NSString_SKExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 89E4E74A2964216F002DBA6F /* NSString_SKExtensions.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
 		89E4E74D2964216F002DBA6F /* NSString_SKExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 89E4E74A2964216F002DBA6F /* NSString_SKExtensions.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
 		89E4E755296427E5002DBA6F /* NSImage_SKExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 89E4E753296427E5002DBA6F /* NSImage_SKExtensions.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
@@ -2535,6 +2534,9 @@
 		BB74DA772AC41182006EDFE7 /* NSFont+KMExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB74DA762AC41182006EDFE7 /* NSFont+KMExtension.swift */; };
 		BB74DA782AC41182006EDFE7 /* NSFont+KMExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB74DA762AC41182006EDFE7 /* NSFont+KMExtension.swift */; };
 		BB74DA792AC41182006EDFE7 /* NSFont+KMExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB74DA762AC41182006EDFE7 /* NSFont+KMExtension.swift */; };
+		BB74DA7B2AC41DE9006EDFE7 /* NSString+KMExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB74DA7A2AC41DE9006EDFE7 /* NSString+KMExtension.swift */; };
+		BB74DA7C2AC41DE9006EDFE7 /* NSString+KMExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB74DA7A2AC41DE9006EDFE7 /* NSString+KMExtension.swift */; };
+		BB74DA7D2AC41DE9006EDFE7 /* NSString+KMExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB74DA7A2AC41DE9006EDFE7 /* NSString+KMExtension.swift */; };
 		BB7507E929861C37002DBDB1 /* PasswordWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = BB7507E629861C37002DBDB1 /* PasswordWindowController.m */; };
 		BB7507EA29861C37002DBDB1 /* PasswordWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = BB7507E629861C37002DBDB1 /* PasswordWindowController.m */; };
 		BB7507EB29861C37002DBDB1 /* PasswordWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = BB7507E629861C37002DBDB1 /* PasswordWindowController.m */; };
@@ -4572,6 +4574,7 @@
 		BB6DD820293497B6001F0544 /* KMSecureEncryptModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMSecureEncryptModel.swift; sourceTree = "<group>"; };
 		BB6DD8242934D056001F0544 /* KMSecureEncryptSuccessTipView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMSecureEncryptSuccessTipView.swift; sourceTree = "<group>"; };
 		BB74DA762AC41182006EDFE7 /* NSFont+KMExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSFont+KMExtension.swift"; sourceTree = "<group>"; };
+		BB74DA7A2AC41DE9006EDFE7 /* NSString+KMExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSString+KMExtension.swift"; sourceTree = "<group>"; };
 		BB7507E629861C37002DBDB1 /* PasswordWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PasswordWindowController.m; sourceTree = "<group>"; };
 		BB7507E729861C37002DBDB1 /* PasswordWindowController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = PasswordWindowController.xib; sourceTree = "<group>"; };
 		BB7507E829861C37002DBDB1 /* PasswordWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PasswordWindowController.h; sourceTree = "<group>"; };
@@ -7671,6 +7674,7 @@
 				BBCE57172A72723600508EFC /* NSResponder+KMExtension.swift */,
 				BB3A81B42AC2C0F4006FC66C /* NSObject+KMExtension.swift */,
 				BB74DA762AC41182006EDFE7 /* NSFont+KMExtension.swift */,
+				BB74DA7A2AC41DE9006EDFE7 /* NSString+KMExtension.swift */,
 			);
 			path = Category;
 			sourceTree = "<group>";
@@ -10798,6 +10802,7 @@
 				ADC075EA2987A38C006C752F /* KMBatchConverPDFCSVView.swift in Sources */,
 				BBD54ED42A1CBD720012A230 /* NSView+KMExtension.swift in Sources */,
 				9FAAA332290BD0A20046FFCE /* KMHistoryFileCollectionViewItem.swift in Sources */,
+				BB74DA7B2AC41DE9006EDFE7 /* NSString+KMExtension.swift in Sources */,
 				AD1CA4112A061CCD0070541F /* KMAnnotationScreenColorViewItem.swift in Sources */,
 				AD867FC129DFC39400F00440 /* KMBOTAAnnotationItem.swift in Sources */,
 				BBDA8A6D2A31F9A6006A2C4E /* KMDesignStepperView.swift in Sources */,
@@ -11031,7 +11036,6 @@
 				BB4DD043299B291A00E80DF6 /* KMCloudNoNetworkView.swift in Sources */,
 				BB49ECF6293F44DC00C82CA2 /* KMConvertExcelWindowController.swift in Sources */,
 				BBC348432956A638008D2CD1 /* KMEditBackgroundController.swift in Sources */,
-				89E4E74B2964216F002DBA6F /* NSString_SKExtensions.m in Sources */,
 				9F0CB49F29683E2600007028 /* KMPropertiesPanelSizeSubVC.swift in Sources */,
 				BB2EDF54296E815E003BCF58 /* KMPageEditBaseItemView.swift in Sources */,
 				9F1FE4EA29406E4700E952CA /* NSBezierPath+MCAdditions.m in Sources */,
@@ -11535,6 +11539,7 @@
 				9F0CB5122986565700007028 /* KMDesignToken+BorderRadius.swift in Sources */,
 				BB86C1EE28F544F4005AD968 /* CPDFListView+Event.m in Sources */,
 				9F81ADC729B9B12C002251F4 /* NSButton+DesignToken.swift in Sources */,
+				BB74DA7C2AC41DE9006EDFE7 /* NSString+KMExtension.swift in Sources */,
 				BBEC00C8295C319400A26C98 /* KMBatesManager.swift in Sources */,
 				ADA9102B2A272CE2003352F0 /* KMEditPDFTextManager.swift in Sources */,
 				BB147021299DC0D100784A6A /* OIDServiceDiscovery.m in Sources */,
@@ -12484,6 +12489,7 @@
 				9F0CB4DF2986554D00007028 /* KMDesignToken+HorizontalPadding.swift in Sources */,
 				AD44D654292C9E7900A94554 /* KMImageToPDFChooseView.swift in Sources */,
 				BBB9B318299A5D6D004F3235 /* KMDropboxManager.m in Sources */,
+				BB74DA7D2AC41DE9006EDFE7 /* NSString+KMExtension.swift in Sources */,
 				9FCFEC6A2AC2EAD500EAD2CB /* CPDFListViewColorMenuItemView.swift in Sources */,
 				BB8F4559295AA1270037EA22 /* KMHeaderFooterPropertyInfoController.swift in Sources */,
 				89752DBA2936F9B9003FF08E /* NSButton+TitleColor.m in Sources */,

+ 1 - 1
PDF Office/PDF Master/Class/Common/Base/KMBaseViewController.swift

@@ -85,7 +85,7 @@ class KMBaseViewController: NSViewController {
         for (index, fileUrl) in fileUrls.enumerated() {
             let filePath = fileUrl.path
             let folderPath = "convertToPDF_\(index).pdf"
-            let savePath = folderPath.kUrlToPDFFolderPath()
+            let savePath: String? = folderPath.kUrlToPDFFolderPath() as String
             if (savePath == nil) {
                 continue
             }

+ 1 - 1
PDF Office/PDF Master/Class/Common/Category/NSFont+KMExtension.swift

@@ -8,7 +8,7 @@
 import Foundation
 
 private var _layoutManager: NSLayoutManager?
-extension NSFont {
+@objc extension NSFont {
     func defaultViewLineHeight() -> CGFloat {
         if (_layoutManager == nil) {
             _layoutManager = NSLayoutManager()

+ 49 - 0
PDF Office/PDF Master/Class/Common/Category/NSString+KMExtension.swift

@@ -0,0 +1,49 @@
+//
+//  NSString+KMExtension.swift
+//  PDF Master
+//
+//  Created by tangchao on 2023/9/27.
+//
+
+import Foundation
+
+extension NSString {
+    func kUrlToPDFFolderPath() -> NSString {
+        guard let path = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).last else {
+            return ""
+        }
+        
+        return path.stringByAppendingPathComponent(Bundle.main.bundleIdentifier ?? "PDF Master bundleIdentifier").stringByAppendingPathComponent(self as String) as NSString
+    }
+    
+    @objc var typeName: NSString {
+        get {
+            let comment = "Description for export"
+            if (self.isEqual(to: "FreeText")) {
+                return NSLocalizedString("Text Box", comment: comment) as NSString
+            } else if (self.isEqual(to: "Note")) {
+                return NSLocalizedString("Anchored Note", comment: comment) as NSString
+            } else if (self.isEqual(to: "Circle")) {
+                return NSLocalizedString("Circle", comment: comment) as NSString
+            } else if (self.isEqual(to: "Square")) {
+                return NSLocalizedString("Rectangle", comment: comment) as NSString
+            } else if (self.isEqual(to: "Highlight")) {
+                return NSLocalizedString("Highlight", comment: comment) as NSString
+            } else if (self.isEqual(to: "Underline")) {
+                return NSLocalizedString("Underline", comment: comment) as NSString
+            } else if (self.isEqual(to: "Strikeout")) {
+                return NSLocalizedString("Strikethrough", comment: comment) as NSString
+            } else if (self.isEqual(to: "Arrow")) {
+                return NSLocalizedString("Arrow", comment: comment) as NSString
+            } else if (self.isEqual(to: "Line")) {
+                return NSLocalizedString("Line", comment: comment) as NSString
+            } else if (self.isEqual(to: "Freehand")) {
+                return NSLocalizedString("Freehand", comment: comment) as NSString
+            } else if (self.isEqual(to: "Stamp")) {
+                return NSLocalizedString("Stamp", comment: comment) as NSString
+            }
+            return NSLocalizedString(self as String, comment: comment) as NSString
+        }
+    }
+}
+

+ 13 - 13
PDF Office/PDF Master/Class/Home/ViewController/KMAIOpenPDFFilesVC.swift

@@ -140,7 +140,7 @@ class KMAIOpenPDFFilesVC: NSViewController {
         let filePath = url.path
         
         let fileName: NSString = url.lastPathComponent as NSString
-        let savePath = fetchUniquePath(fileName.kUrlToPDFFolderPath()).deletingLastPathComponent
+        let savePath = fetchUniquePath(fileName.kUrlToPDFFolderPath() as String).deletingLastPathComponent
 
         let imageName = NSString(string: NSString(string: filePath).lastPathComponent).deletingPathExtension
         
@@ -194,21 +194,21 @@ class KMAIOpenPDFFilesVC: NSViewController {
         let folderPath = "convertToPDF.pdf"
         let savePath = folderPath.kUrlToPDFFolderPath()
         
-        if (!FileManager.default.fileExists(atPath: savePath!.deletingLastPathComponent as String)) {
-            try?FileManager.default.createDirectory(atPath: savePath!.deletingLastPathComponent as String, withIntermediateDirectories: true, attributes: nil)
+        if (!FileManager.default.fileExists(atPath: savePath.deletingLastPathComponent as String)) {
+            try?FileManager.default.createDirectory(atPath: savePath.deletingLastPathComponent as String, withIntermediateDirectories: true, attributes: nil)
         }
         
-        if (!FileManager.default.fileExists(atPath: savePath! as String)) {
-            FileManager.default.createFile(atPath: savePath! as String, contents: nil)
+        if (!FileManager.default.fileExists(atPath: savePath as String)) {
+            FileManager.default.createFile(atPath: savePath as String, contents: nil)
         }
 
         if savePath == nil {
             return
         }
-        KMConvertPDFManagerOC.convertFile(filePath, savePath: savePath!) { success, errorDic in
-            if errorDic != nil || !success || !FileManager.default.fileExists(atPath: savePath!) {
-                if FileManager.default.fileExists(atPath: savePath!) {
-                    try?FileManager.default.removeItem(atPath: savePath!)
+        KMConvertPDFManagerOC.convertFile(filePath, savePath: savePath as String) { success, errorDic in
+            if errorDic != nil || !success || !FileManager.default.fileExists(atPath: savePath as String) {
+                if FileManager.default.fileExists(atPath: savePath as String) {
+                    try?FileManager.default.removeItem(atPath: savePath as String)
                 }
                 let alert = NSAlert.init()
                 alert.alertStyle = .critical
@@ -225,14 +225,14 @@ class KMAIOpenPDFFilesVC: NSViewController {
                 return
             }
             
-            if !savePath!.isPDFValid() {
+            if !(savePath as String).isPDFValid() {
                 let alert = NSAlert()
                 alert.alertStyle = .critical
                 alert.messageText = NSLocalizedString("An error occurred while opening this document. The file is damaged and could not be repaired.", comment: "")
                 alert.runModal()
                 return
             }
-            NSDocumentController.shared.openDocument(withContentsOf: URL(fileURLWithPath: savePath!), display: true) { document, documentWasAlreadyOpen, error in
+            NSDocumentController.shared.openDocument(withContentsOf: URL(fileURLWithPath: savePath as String), display: true) { document, documentWasAlreadyOpen, error in
                 if error != nil {
                     NSApp.presentError(error!)
                     return
@@ -328,7 +328,7 @@ class KMAIOpenPDFFilesVC: NSViewController {
                   (type == "pptx") ||
                   (type == "pptx") {
             let fileName: NSString = String(format: "%@.pdf", NSLocalizedString("Untitled", comment: "")) as NSString
-            let savePath = fetchUniquePath(fileName.kUrlToPDFFolderPath())
+            let savePath = fetchUniquePath(fileName.kUrlToPDFFolderPath() as String)
             openOfficeFile(url: path)
         }
     }
@@ -461,7 +461,7 @@ class KMAIOpenPDFFilesVC: NSViewController {
     
     @IBAction func openBlankPage(_ sender: Any) {
         let fileName: NSString = String(format: "%@.pdf", NSLocalizedString("Untitled", comment: "")) as NSString
-        let savePath = fetchUniquePath(fileName.kUrlToPDFFolderPath())
+        let savePath = fetchUniquePath(fileName.kUrlToPDFFolderPath() as String)
         if (!FileManager.default.fileExists(atPath: savePath.deletingLastPathComponent as String)) {
             try?FileManager.default.createDirectory(atPath: savePath.deletingLastPathComponent as String, withIntermediateDirectories: true, attributes: nil)
         }

+ 4 - 4
PDF Office/PDF Master/Class/Home/ViewController/KMHomeViewController+Action.swift

@@ -455,7 +455,7 @@ extension KMHomeViewController {
                   (type == "pptx") ||
                   (type == "pptx") {
             let fileName: NSString = String(format: "%@.pdf", NSLocalizedString("Untitled", comment: "")) as NSString
-            let savePath = fetchUniquePath(fileName.kUrlToPDFFolderPath())
+            let savePath = fetchUniquePath(fileName.kUrlToPDFFolderPath() as String)
             openOfficeFile(url: path)
         }
     }
@@ -464,7 +464,7 @@ extension KMHomeViewController {
         var filePath = url.path
         
         let fileName: NSString = url.lastPathComponent as NSString
-        let savePath = fetchUniquePath(fileName.kUrlToPDFFolderPath()).deletingLastPathComponent
+        let savePath = fetchUniquePath(fileName.kUrlToPDFFolderPath() as String).deletingLastPathComponent
 
         let imageName = NSString(string: NSString(string: filePath).lastPathComponent).deletingPathExtension
         
@@ -539,7 +539,7 @@ extension KMHomeViewController {
     func openOfficeFile(url: URL) -> Void {
         let filePath = url.path
         let folderPath = "convertToPDF.pdf"
-        let savePath = folderPath.kUrlToPDFFolderPath()
+        let savePath: String? = folderPath.kUrlToPDFFolderPath() as String
         
         if (!FileManager.default.fileExists(atPath: savePath!.deletingLastPathComponent as String)) {
             try?FileManager.default.createDirectory(atPath: savePath!.deletingLastPathComponent as String, withIntermediateDirectories: true, attributes: nil)
@@ -1236,7 +1236,7 @@ extension KMHomeViewController {
     
     @IBAction func openBlankPage(_ sender: Any) {
         let fileName: NSString = String(format: "%@.pdf", NSLocalizedString("Untitled", comment: "")) as NSString
-        let savePath = fetchUniquePath(fileName.kUrlToPDFFolderPath())
+        let savePath = fetchUniquePath(fileName.kUrlToPDFFolderPath() as String)
         let pdfDocument = CPDFDocument()
         pdfDocument?.insertPage(CGSize(width: 595, height: 842), at: 0)
         pdfDocument?.write(to: URL(fileURLWithPath: savePath))

+ 1 - 1
PDF Office/PDF Master/Class/Home/WindowController/KMURLToPDFWindowController.swift

@@ -188,7 +188,7 @@ class KMURLToPDFWindowController: NSWindowController {
 //        let append2 = searchPath!.stringByAppendingPathComponent("WebPage")
         let append1: NSString = "WebPage"
         let append2 = append1.kUrlToPDFFolderPath()
-        return append2!
+        return append2 as String
     }
     
     @objc func beginSheetModal(for window: NSWindow, completionHandler handler: ((_ filePath: String) -> Void)?) {

+ 0 - 2
PDF Office/PDF Master/Class/PDFWindowController/Side/RightSide/AnnotationProperty/KMAnnotationFontWindowController.m

@@ -6,8 +6,6 @@
 //
 
 #import "KMAnnotationFontWindowController.h"
-//#import "NSUserDefaults_SKExtensions.h"
-#import "NSFont_SKExtensions.h"
 
 @interface KMAnnotationFontWindowController ()
 

+ 3 - 7
PDF Office/PDF Master/Class/PDFWindowController/Side/RightSide/AnnotationProperty/KMAnnotationPropertiesViewController.m

@@ -10,13 +10,9 @@
 #import "KMAnnotationLinkViewController.h"
 #import "KMSelfSignAnnotation.h"
 #import "KMSelfSignAnnotationFreeText.h"
-#import "NSString_SKExtensions.h"
+//#import "NSString_SKExtensions.h"
 #import "KMAnnotationStampViewController.h"
-#if VERSION_DMG
 #import <PDF_Master-Swift.h>
-#else
-#import <PDF_Master-Swift.h>
-#endif
 #import "KMSignatureAnnotationViewController.h"
 #import "CSelfSignAnnotation.h"
 #import "CSelfSignAnnotationFreeText.h"
@@ -150,7 +146,7 @@
                 self.titleLabel.stringValue = NSLocalizedString(@"Date", nil);
             }
         } else {
-            self.titleLabel.stringValue = [[annotation type] typeName];
+            self.titleLabel.stringValue = [annotation type].typeName;
         }
     } else if ([annotation isKindOfClass:[CPDFSignatureWidgetAnnotation class]] ||
                [annotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
@@ -173,7 +169,7 @@
             self.titleLabel.stringValue = NSLocalizedString(@"Date", nil);
         }
     } else {
-        self.titleLabel.stringValue = [[annotation type] typeName];
+        self.titleLabel.stringValue = [annotation type].typeName;
     }
     
     CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];

+ 0 - 1
PDF Office/PDF Master/PDF_Master DMG-Bridging-Header.h

@@ -47,7 +47,6 @@
 #import <ObjectiveDropboxOfficial/ObjectiveDropboxOfficial.h>
 #import "KMCloudOperation.h"
 #import "KMSecondaryViewController.h"
-#import "NSString_SKExtensions.h"
 #import "NSButton+TitleColor.h"
 //
 #import "KMPrintAccessoryController_OC.h"

+ 0 - 1
PDF Office/PDF Master/PDF_Master-Bridging-Header.h

@@ -46,7 +46,6 @@
 #import <ObjectiveDropboxOfficial/ObjectiveDropboxOfficial.h>
 #import "KMCloudOperation.h"
 #import "KMSecondaryViewController.h"
-#import "NSString_SKExtensions.h"
 #import "NSButton+TitleColor.h"
 //
 #import "KMPrintAccessoryController_OC.h"