You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
本库的 iOS 核心正在迁移到 Swift(Swift-Migration.md)。维护者已决定(2026-11-19 确认):CYLTabBarController、CYLPlusButton、CYLBaseNavigationController、CYLBaseViewController、CYLBaseTableViewController 与 CYLTabButtonBlockAnimation 将成为 open 的 Swift 类。Swift 类不能在 Objective-C 中被继承,因此 App 中继承这些类的子类需要用 Swift 编写。本文说明为什么、要改什么、以及如何一步一步完成。
The iOS core of this library is moving to Swift (Swift-Migration.md). The maintainer decided (confirmed 2026-11-19) that CYLTabBarController, CYLPlusButton, CYLBaseNavigationController, CYLBaseViewController, CYLBaseTableViewController and CYLTabButtonBlockAnimation become open Swift classes. A Swift class cannot be subclassed in Objective-C, so an app's subclasses of these classes must be written in Swift. This guide says why, what changes, and how to do it step by step.
进行中:CYLPlusButton 自第 109 步起已是 Swift 类(尚未发布);其余类目前仍是 Objective-C,现有的 Objective-C 子类照常工作。它们在迁移第 ② 阶段变为 Swift 类(Swift-Migration.md,"Plan");该版本发布时,本文与发布说明会写明版本号。现在就可以按下文把子类改写为 Swift:同样适用于当前的 Objective-C 类,切换时无需再改。
In progress: CYLPlusButton is a Swift class since step 109 (not released yet); the other classes are still Objective-C today, and existing Objective-C subclasses of them keep working. They become Swift classes in phase ② of the migration (Swift-Migration.md, "Plan"); the release that ships it will be named here and in the release notes. You can port your subclasses to Swift now, as below: they also work with today's Objective-C classes, so nothing changes again at the switch.
[CN]为什么
[EN]Why
中文
English
Swift 把类导出给 Objective-C 时带有 objc_subclassing_restricted:Objective-C 可以使用 Swift 类,但不能继承它。最终目标是 Swift Package Manager 中只有一个 Swift target(Objective-C 外壳无法放进去),因此保留 Objective-C 外壳类的方案被替换为 open 的 Swift 类。
Swift exports its classes to Objective-C with objc_subclassing_restricted: Objective-C can use a Swift class but cannot subclass it. The goal is one Swift target in Swift Package Manager, which cannot hold Objective-C shell classes, so the earlier plan of thin Objective-C shells was replaced by open Swift classes.
What does not change: Objective-C code can still create, configure and call these classes (every method keeps its selector); only subclassing needs Swift.
1. Find the subclasses: search the app for @interface … : CYLTabBarController, : CYLPlusButton, : CYLBaseNavigationController, : CYLBaseViewController, : CYLBaseTableViewController, : CYLTabButtonBlockAnimation, and for subclasses of those subclasses.
2. Add Swift to the app: when you add the first Swift file to an Objective-C project, Xcode offers to create a bridging header (<App>-Bridging-Header.h); accept it and #import <CYLTabBarController/CYLTabBarController.h> there (CocoaPods / Carthage), or write import CYLTabBarController in the Swift files. Set SWIFT_VERSION (e.g. 5.0).
3. 逐个改写子类,保持类名:写成 @objc(CYLHomeViewController) class CYLHomeViewController: CYLBaseTableViewController。@objc(名称) 让 Objective-C 代码(以及 storyboard、NSClassFromString、配置文件中的类名)继续使用原来的名称。
3. Port each subclass, keeping its name: @objc(CYLHomeViewController) class CYLHomeViewController: CYLBaseTableViewController. @objc(Name) keeps the Objective-C name for Objective-C code, storyboards, NSClassFromString and class names in configuration files.
5. Registering a plus button: Objective-C subclasses often call [super registerPlusButton] in +load; Swift has no +load, so call CYLPlusButtonSubclass.register() explicitly before creating the CYLTabBarController (e.g. in application(_:didFinishLaunchingWithOptions:) or the root view controller).
6. Overridden methods: - (void)viewDidLoad becomes override func viewDidLoad(); the class methods of CYLPlusButtonSubclassing (+plusButton, +indexOfPlusButtonInTabBar, +plusChildViewController, …) become static func (or class func when a subclass overrides them again).
| 7. 全局变量变为只读(第 109 步起):CYLExternPlusButton、CYLPlusChildViewController 与 CYLPlusButtonWidth 现在是 Swift 变量,Objective-C 通过宏读取;为它们赋值的代码不再能编译(它们只是库保存的值,读取不受影响)。 | 7. The globals are read-only (since step 109): CYLExternPlusButton, CYLPlusChildViewController and CYLPlusButtonWidth are Swift variables, read by Objective-C through macros; code that assigned them no longer compiles (they are values the library keeps; reading them is unaffected). |
| 8. +multiplerInCenterY(已废弃)现在是 CYLPlusButtonSubclassing 的可选方法,不再是 CYLPlusButton 的方法:Swift 子类实现它时去掉 override。 | 8. +multiplerInCenterY (deprecated) is now an optional method of CYLPlusButtonSubclassing, no longer a method of CYLPlusButton: a Swift subclass that implements it drops override. |
| 9. CYLTabBarItemImagePlaceholderWidth / …Height 变为只读(第 114 步起):在 Objective-C 中改用 CYLConstants.tabBarItemImagePlaceholderSize 设置。 | 9. CYLTabBarItemImagePlaceholderWidth / …Height are read-only in Objective-C (since step 114): set them with CYLConstants.tabBarItemImagePlaceholderSize. |
// After: MainTabBarController.swift (Objective-C still sees it as MainTabBarController)
@objc(MainTabBarController)finalclassMainTabBarController:CYLTabBarController{overridefuncviewDidLoad(){super.viewDidLoad()delegate=self}}
This repository's own Objective-C subclasses (the Objective-C example's MainTabBarController, CYLFlatDesignMainTabBarController, CYLPlusButtonSubclass and its subclasses, the home / message / mine / same-city / details view controllers, the library's CYLConfigurationPlusButton, and the tests' CYLTestPlusButton and CYLSuperCallingTabBarController) are ported with these steps, one by one, and serve as references (Swift-Migration.md, from step 107).
[CN]发布说明(TODO)
[EN]Release notes (TODO)
中文
English
第 ② 阶段发布时加入发布说明的条目(版本号待定):"CYLTabBarController、CYLPlusButton、CYLBaseNavigationController、CYLBaseViewController、CYLBaseTableViewController 与 CYLTabButtonBlockAnimation 现在是 Swift 类。Objective-C 代码仍可使用它们,但其子类必须用 Swift 编写:见 docs/Subclassing-In-Swift.md。CYLTabBarBadgeView 已是 Swift 类,同样只能在 Swift 中继承。"
The entry for the release notes when phase ② ships (version to be decided): "CYLTabBarController, CYLPlusButton, CYLBaseNavigationController, CYLBaseViewController, CYLBaseTableViewController and CYLTabButtonBlockAnimation are now Swift classes. Objective-C code can still use them, but subclasses must be written in Swift: see docs/Subclassing-In-Swift.md. CYLTabBarBadgeView is already a Swift class and can likewise be subclassed only in Swift."