参考资料
网络库的转换内容,需要注意的事项
- 用新的网络库,请求接口携带cookie进行的安全验证问题 (需要与objc的使用进行隔离)
- 如果使用ASI进行请求时,混编是否会出现类型转换的问题
- 需要对CKDataResult,CKDataService进行桥接,进行试验
- 数据请求模型的构建,会出现继承Object-c出现的问题 比如CKListDataModel
- 新出一套的话需要对网络层进行封装处理,关键点在于cookie处
- JsonKit的选择,model类型转换的问题
图片加载的问题
缓存的问题
UI框架层的问题
- 网络请求层,下拉刷新,上拉加载更多的框架需要按照Swift的思想重新封装(需要与objc的使用进行隔离)
使用Swift重构 方案
需要自行完善的SDK
- UIKit 扩展
- Foundation 扩展
- 网络层 扩展
- 图片加载层 扩展 (如果用到小视频时需要此扩展)
- 下拉刷新,上拉加载更多的逻辑 扩展
- 路由层的处理
- 定位问题
- 分享问题
- 扫描库的问题
- searchKit scanKit 等等的依赖问题解决,使用自己的依赖的时候不要用尖括号
- webController的支持,包括JSbridgeWebController
制作模拟器和真机都兼容的动态库需要加入的shell脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| if [ "${ACTION}" = "build" ] then INSTALL_DIR=${SRCROOT}/Products/${PROJECT_NAME}.framework DEVICE_DIR=${BUILD_ROOT}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework SIMULATOR_DIR=${BUILD_ROOT}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework if [ -d "${INSTALL_DIR}" ] then rm -rf "${INSTALL_DIR}" fi mkdir -p "${INSTALL_DIR}" cp -R "${DEVICE_DIR}/" "${INSTALL_DIR}/" lipo -create "${DEVICE_DIR}/${PROJECT_NAME}" "${SIMULATOR_DIR}/${PROJECT_NAME}" -output "${INSTALL_DIR}/${PROJECT_NAME}" open "${DEVICE_DIR}" open "${SRCROOT}/Products" fi
|
混编需要注意的地方
1、swift不认识NS_ENUM宏,直接typedef enum…
2、DispatchQueue.main.async
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| DispatchQueue.main.async { let topC: UIViewController = UIApplication.shared.topViewController() if let topNav = topC.navigationController { if controller.isKind(of: UINavigationController.self) { topNav.present(controller, animated: true, completion: nil) } else { topNav.pushViewController(controller, animated: true) } } else { if controller.isKind(of: UINavigationController.self) { topC.present(controller, animated: true, completion: nil) } else { topC.present(CLHNavigationController.init(rootViewController: controller), animated: true, completion: nil) } } }
|
3、注意NSDictionary和Dictionary的区别,通过objc传值过来的都是NSDictionary
4、NSthread 要用Thread
1 2 3 4
| while waitTime < 8.0 && CLHCoreUtil.mainController() == nil { Thread.sleep(forTimeInterval: 0.1) waitTime = waitTime + 0.1 }
|
5、注册通知或者prformSelector调用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| let notificationDidOpenName = NSNotification.Name(APP_EVENT_PUSH_NOTIFICATION_DID_OPEN) NotificationCenter.default.addObserver(self, selector: #selector(pushNotificationDidOpen(notification:)), name: notificationDidOpenName, object: nil) let notificationDidReciveName = NSNotification.Name(APP_EVENT_PUSH_NOTIFICATION_DID_RECIVE) NotificationCenter.default.addObserver(self, selector: #selector(pushNotificationDidOpen(notification:)), name: notificationDidReciveName, object: nil) @objc func pushNotificationDidOpen(notification: NSNotification) { } @objc func pushNotificationDidRecive(notification: NSNotification) { } self.performSelector(inBackground: #selector(safePushViewController(controller:)), with: navController) @objc func safePushViewController(controller: UIViewController) { }
|
6、 UIAlertView 之坑,otherButtonTitle的问题
7、如何添加warning标识,添加 New Run Script Phase,点击了之后就出现了下图的Run Script栏 ,添加如下shell脚本
1 2 3
| TAGS="TODO:|FIXME:" echo "searching ${SRCROOT} for ${TAGS}" find "${SRCROOT}" \( -name "*.swift" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).*\$" | perl -p -e "s/($TAGS)/ warning: \$1/"
|
8、 CGRect 和 枚举实例,如下代码:
1 2 3 4 5
| let shadowImageView = UIImageView(image: UIImage.init(named: "leftside_shadow_bg")) shadowImageView.frame = CGRect(x: -10, y: 0, width: 10, height: self.window!.rootViewController!.view.bounds.height) shadowImageView.autoresizingMask = [.flexibleWidth, .flexibleHeight] self.window!.rootViewController!.view.addSubview(shadowImageView)
|
9、 swift中混编调用oc的实例方法和静态方法 QCPWelcomeView 举例
10、关于私有库中bundle资源文件的管理,各个framework自己管理自己的bundle文件,不要依赖其他私有库或者从主项目中获取,可以传入实例化的资源问价载体