Merged
Conversation
…rn APIs
This commit migrates three core MMKit Category extensions from Objective-C to Swift, establishing a foundation for the gradual modernization of the Easydict codebase.
**Migrated Components:**
1. **Color Management** (`NSColor+MM` → `Color+Hex.swift`)
- Introduces SwiftUI `Color` support with modern API design
- Implements comprehensive hex string parsing (3/6/8-bit formats)
- Maintains full Objective-C compatibility via `@objc` annotations
2. **Image Export** (`NSImage+MM` → `NSImage+Export.swift`)
- Implements modern error handling with `throws` instead of boolean returns
- Adds Swift-style computed properties (`pngData`, `jpegData`)
- Provides dual Swift and Objective-C APIs for seamless interoperability
3. **Text Layout** (`NSString+MM` → `String+Layout.swift`)
- Migrates font-based layout calculation methods to Swift
- Offers idiomatic Swift API (`width(with:)`, `height(with:)`, `size(with:)`)
- Preserves all original `mm_` prefixed methods for backward compatibility
**Technical Strategy:**
- **Dual API Design**: All Swift extensions provide both modern Swift APIs and legacy `mm_` prefixed methods
- **Full Compatibility**: Objective-C code continues to work unchanged through `@objc` annotations
- **Modern Swift Features**: Leverages optionals, error handling, and other Swift idioms
- **Comprehensive Documentation**: Each method includes detailed documentation with usage examples
**File Changes:**
- Added: `Color+Hex.swift`, `NSImage+Export.swift`, `String+Layout.swift`
- Removed: `NSColor+MM.{h,m}`, `NSImage+MM.{h,m}` (fully migrated)
- Modified: `NSString+MM.{h,m}` (partially migrated, retained used methods)
- Updated: `PrefixHeader.pch` (added `Easydict-Swift.h` import), `Easydict-Bridging-Header.h`
- Updated: Project configuration files
**Impact:** This refactoring reduces the Objective-C codebase by ~200 lines while maintaining 100% backward compatibility. It establishes a clear migration pattern for future Objective-C to Swift conversions.
…tension This commit resolves SwiftLint warnings related to variable naming in the Color+Hex.swift file, ensuring compliance with the project's code style guidelines. **Changes Made:** 1. **Variable Naming Improvements** - Renamed single-letter variables (`a`, `r`, `g`, `b`) to descriptive names (`alphaComp`, `redComp`, `greenComp`, `blueComp`) - Updated parameter names from `r,g,b` to `red,green,blue` in public APIs - Applied consistent naming conventions across all color component variables 2. **Code Quality Enhancements** - Improved readability by using descriptive variable names - Maintained full backward compatibility with existing Objective-C interfaces - Added `@discardableResult` attribute to suppress unused return value warnings **Technical Details:** - **Color+Hex.swift**: 17 identifier naming violations resolved - **NSImage+Export.swift**: Added `@discardableResult` to suppress unused return value warning - All changes maintain the existing API surface and behavior - Objective-C compatibility preserved through proper `@objc` annotations This cleanup ensures the codebase adheres to SwiftLint standards while maintaining the improved functionality introduced in the previous refactor commit. No functional changes were made to the color management or image export features.
…o Swift Migrate NSButton, NSDictionary, and NSPasteboard category extensions from Objective-C to Swift while maintaining full Objective-C compatibility through @objc annotations. Changes: - Add NSButton+Extension.swift with modern Swift API and @objc(mm_isOn) compatibility - Add Dictionary+ObjCCompat.swift with inverted() method and @objc(mm_reverseKeysAndObjectsDictionary) compatibility - Add NSPasteboard+ObjCCompat.swift with setString(_:) method and @objc(mm_generalPasteboardSetString:) compatibility - Remove old Objective-C implementation files (.h/.m) - Update PrefixHeader.pch to remove deprecated imports - Update Xcode project file to reference new Swift files Maintains zero functional changes - all existing Objective-C code continues to work through the compatibility layer.
This commit migrates Objective-C category extensions from MMKit/Category to modern Swift equivalents, maintaining full Objective-C compatibility. Migrated Extensions: - NSArray+MM → Array+ObjCCompat (mm_map, mm_where, mm_find, mm_combine, mm_objectToIndexDictionary) - NSString+MM → String+ObjCCompat (mm_stringByCombineComponents, mm_urlencode) - NSUserDefaults+MM → UserDefaults+ObjCCompat (mm_read, mm_save) - NSAttributedString+MM → NSAttributedString+ObjCCompat (mm_attributedStringWithString, mm_getTextWidth, mm_getTextHeightWithWidth, mm_getTextSize) - NSMutableAttributedString+MM → NSMutableAttributedString+ObjCCompat (mm_appendString, mm_setTextColor, mm_setTextFont) - NSView+MM → NSView+ObjCCompat (x, y, width, height, top, left, bottom, right, centerX, centerY, origin, size, center, topLeft, leftBottom, bottomRight, topRight) - NSWindow+MM → NSWindow+ObjCCompat (x, y, width, height, top, left, bottom, right, centerX, centerY, origin, size, centerPoint, topLeft, leftBottom, bottomRight, topRight) - NSPasteboard+MM → NSPasteboard+ObjCCompat (reorganized file structure to Pasteboard/) Key Changes: - All new Swift files use @objc annotations to maintain Objective-C compatibility - Original function names preserved via @objc(selector:) for seamless integration - Swift-style naming used internally while exposing ObjC-compatible APIs - Deleted corresponding .h/.m files after successful migration - Reorganized NSPasteboard extensions into Pasteboard/ directory - Updated Xcode project structure and removed bridging header references - Added .claude/settings.local.json to .gitignore for local development This migration enables gradual modernization of the codebase while maintaining zero functional changes and full backward compatibility with existing Objective-C code.
This commit migrates MMOrderedDictionary from Objective-C to Swift while maintaining full backward compatibility with existing Objective-C code. Implementation Details: - Created OrderedDictionary.swift as the core Swift implementation - Created OrderedDictionary+Variadic category for variadic argument support - Resolved circular dependency issues with forward declarations - Fixed block parameter types to use UInt for NSUInteger compatibility - Deleted original MMOrderedDictionary.h and .m files - Updated all references to use the new Swift implementation The migration preserves all existing functionality while providing a modern Swift implementation internally.
This commit fixes documentation parameter names that didn't match the actual Objective-C method signatures generated by Swift. The warnings occurred because the documentation referenced parameter names like 'withIntR' and 'alhpa' that don't exist in the generated Objective-C header. The Swift compiler generates specific Objective-C method signatures with parameter names 'red', 'green', 'blue', and 'alpha', so the documentation needed to match these exact names. Changes: - Fixed parameter names in mm_colorWithIntR:g:b: documentation - Fixed parameter names in mm_colorWithIntR:g:b:alpha: documentation - Updated return value documentation for mm_hexStringFromColor:
This commit removes the unused MMTool Objective-C files and related code. MMTool contained a single C-style function MMPointInRect for checking if a point is inside a rectangle (including border). This functionality is no longer needed in the codebase. Changes: - Deleted MMTool.h and MMTool.m implementation files - Removed getMouseLocatedScreen method from EZWindowManager.m that was using MMPointInRect - Removed MMTool.h import from PrefixHeader.pch - Updated Xcode project configuration to remove references to deleted files
This commit refactors the Swift extension file organization to improve code structure and maintainability. Changes: - Moved Color+Hex.swift from AppKit/ to Color/ directory for better categorization - Moved NSMenu+PopUpBelowView.swift from AppKit/ to NSMenu/ directory - Updated Xcode project structure to reflect the new file organization This reorganization separates extensions by their primary domain (Color, NSMenu) rather than grouping them under a generic AppKit category, making the codebase more organized and easier to navigate.
This commit migrates the Google Translate service from Objective-C to Swift. Key changes: - Create GoogleService.swift as the Swift implementation of EZGoogleTranslate - Delete the original EZGoogleTranslate.h and EZGoogleTranslate.m files - Use @objc(EZGoogleTranslate) attribute to maintain Objective-C compatibility - Update EZDetectManager.m and EZServiceTypes.m to work with the new Swift class - Add String+ObjCCompat extension for Objective-C string compatibility methods - Organize the new file under Easydict/Swift/Service/Google/ directory
This commit completes the Swift migration by adopting the native Swift class name throughout the codebase. Changes: - Remove @objc(EZGoogleTranslate) attribute from GoogleService class - Update EZDetectManager.m to use GoogleService instead of EZGoogleTranslate - Update EZServiceTypes.m service type mapping to reference GoogleService class
…t warnings This commit refactors GoogleService.swift by splitting it into multiple extension files to address SwiftLint violations. Key changes: - Create GoogleService+Language.swift for language code mapping methods - Create GoogleService+Translate.swift for WebApp and GTX translate methods - Reduce main file from 880+ lines to ~275 lines - Fix type_body_length violation (was 753 lines, now under 500) - Fix file_length violation (was 911 lines, now under 900) - Fix various other warnings including: - Closure parameter position violations - Unused variable warnings - Unreachable catch blocks - String interpolation debug description warning - var to let changes for constants
This commit updates Xcode project configuration files, likely auto-generated by Xcode 16.1. Changes: - Update LastUpgradeCheck from 2600 to 2610 - Reorder memory debugging options (MallocStackLogging and MallocScribble) - Remove unused entitlements (apple-events and allow-jit)
Move the JavaScript signing file from the Objective-C Google service directory to the Swift Google service directory, consolidating all Google service files in one location.
This commit migrates the DeepL translation service from Objective-C to Swift. - Create DeepLService.swift as the main service class with @objc(EZDeepLTranslate) for Obj-C compatibility - Create DeepLTranslateResponse.swift with Codable models for API responses - Create DeepLService+Translate.swift extension for web and official API translation methods - Remove EZDeepLTranslate.h/m and related Objective-C files - Update bridging header and imports to use the new Swift implementation - Update DeepLTranslate+ConfigurableService.swift to extend DeepLService
Add `// MARK: -` comments to organize code sections in Google and DeepL service files for better code navigation and readability. - GoogleService.swift: Add MARK sections for JavaScript Context, HTTP Session Managers, QueryService Override, Service Type & Configuration, Word Link, Supported Languages, Language Detection, Text to Audio, Language Code Helpers, and Audio URL - GoogleService+Translate.swift: Add MARK sections for WebApp Translate, WebApp Network Request, TKK Management, GTX Translate, GTX Translation Processing, and Language Detection - GoogleService+Language.swift: Add MARK sections for Text Length Helper, Language Code Mapping, and Language from Code - DeepLService.swift: Add MARK sections for Service Type & Configuration, Word Link, Supported Languages, Translate, Private Properties, Language Code Mapping, and Language Variant Helper - DeepLService+Translate.swift: Add MARK sections for Web Translate, Web Translate Response Parser, Official API Translate, Official API Response Parser, and Request Helper Methods
Rewrite NiuTrans translation service from Objective-C to Swift, following the same pattern used for DeepL migration. Changes: - Add NiuTransService.swift as the main service class with @objc(EZNiuTransTranslate) attribute for Objective-C compatibility - Add NiuTransTranslateResponse.swift with Codable structs replacing MJExtension - Update NiuTransTranslate+ConfigurableService.swift to extend NiuTransService - Update APIKey.swift extension from EZNiuTransTranslate to NiuTransService - Remove EZNiuTransTranslate.h import from bridging header and EZServiceTypes.m - Delete Objective-C files: EZNiuTransTranslate.h/m, EZNiuTransTranslateResponse.h/m - Add String.truncated() extension method
This commit migrates the Bing translation service from Objective-C to Swift, continuing the codebase modernization effort. Changes include: - Create BingService.swift as the main service class with @objc(EZBingService) annotation for Objective-C compatibility - Create BingConfig.swift for configuration management with Codable support - Create BingRequest.swift for network requests handling - Create BingTranslateResponse.swift and BingLookupResponse.swift for Codable response models replacing MJExtension - Create BingService+Translate.swift for translation logic with helper methods - Move BingLanguageVoice.swift to Swift/Service/Bing directory - Remove all Objective-C Bing service files (EZBingService, EZBingRequest, EZBingConfig, EZBingTranslateModel, EZBingLookupModel) - Update bridging header and EZServiceTypes.m imports - Update BingService+ConfigurableService.swift extension
- Remove unneeded synthesized initializer in BingLanguageVoice struct - Remove unused self capture in BingRequest closure - Fix unnecessary conditional downcast warning in BingService+Translate - Refactor parseBingDictTranslate to reduce function body length by extracting helper methods (parseMeaningGroup, parsePhonetic, parsePart, parsePhrases, parseSynonymsAndAntonyms, parseCollocation, parseExchanges) - Add BingDictParsedData struct to organize parsed dictionary data
Migrate the Apple Dictionary service from Objective-C to Swift, following the same pattern established by other Swift service migrations. - Create AppleDictionary.swift with @objc(EZAppleDictionary) annotation for Objective-C compatibility - Move apple-dictionary.html to Swift service folder - Add DictionaryKit.h and NSString+EZHandleInputText.h to bridging header - Remove EZAppleDictionary.h/.m imports from dependent Objective-C files - Update Xcode project configuration
Contributor
There was a problem hiding this comment.
Pull request overview
This PR represents a comprehensive refactoring effort moving Objective-C service implementations to Swift and modernizing the codebase. The changes include migrating translation services (Google, DeepL, Bing, NiuTrans) from Objective-C to Swift, removing the MMKit utility library in favor of Swift extensions, and updating type signatures to be more Swift-friendly.
Key Changes:
- Migration of translation services from Objective-C to Swift
- Removal of generic type parameters from MMOrderedDictionary for Objective-C compatibility
- Creation of Swift compatibility extensions for Foundation classes
- Consolidation of utility functions into Swift extensions
Reviewed changes
Copilot reviewed 138 out of 145 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| EasydictSwiftTests/AppleServiceTests.swift | Updated test to use renamed AppleTranslation class |
| EZWindowManager.m | Removed unused getMouseLocatedScreen method |
| Multiple service files (Google, DeepL, Bing, NiuTrans) | Removed Objective-C implementations (migrated to Swift) |
| MMKit category files | Removed utility categories (replaced with Swift extensions) |
| Swift/Utility/Extensions/* | Added new Swift compatibility extensions for NSView, NSWindow, String, UserDefaults, etc. |
| OrderedDictionary.swift | New Swift implementation of MMOrderedDictionary |
| Language+Extension.swift | Updated to work with non-generic MMOrderedDictionary |
| Service configuration views | Updated to use new Swift service class names |
| .gitignore | Removed Claude Code specific ignores |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Jerry23011
approved these changes
Nov 30, 2025
5 tasks
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I plan to gradually rewrite Easydict using Swift + SwiftUI, initially using AI for simple replacement and rewriting, and then we will optimize the rewrite in detail.
This PR is completed code refactoring with the help of Claude Code + Opus 4.5.
Refactor service:
• DeepL
• NiuTrans
• Bing
• AppleDictionary