新浪微博4.0版本移植填坑记录

新浪微博4.0版本移植填坑记录

近期学习刀哥新浪微博3.0版本,现在由于Swift更新到4.0,出现很多BUG,现在整理出来分享。

Swift 4.0 YYModel 无法解析数据

在Swift4.0中,由于YYModel采用运行时来获取Model对应的Key,所以无法获取Swift创建的Model属性。解决方法就是在前面加上@objc属性符号,这样YYModel的运行时就可以获取。

参考资料 https://github.com/ibireme/YYModel/issues/238

当Model中包含Model的时候
[站外图片上传中...(image-a5785a-1522133894499)]
原来使用的是这个方法
[站外图片上传中...(image-abd207-1522133894500)]
现在需要修改在方法前面加上@objc
对应的属性也要加上@objc
[站外图片上传中...(image-b8e13e-1522133894500)]
[站外图片上传中...(image-7832aa-1522133894500)]

Function types cannot have argument labels; use '_' before 'list'

[站外图片上传中...(image-f7fd3d-1522133894500)]
这个问题是Swift4.0后,闭包的参数均为可选,只需要在参数名前面按照提示加上_下划线即可。
[站外图片上传中...(image-1e7269-1522133894500)]

Extraneous argument labels 'isSuccess:shouldRefresh:' in call

[站外图片上传中...(image-c379d7-1522133894500)]
这个是上个问题的衍生问题,由于闭包参数可选,在4.0中就取消了参数名输入,直接输入值即可。
[站外图片上传中...(image-82ea91-1522133894500)]

'NSFontAttributeName' has been renamed to ‘NSAttributedStringKey.font'

在4.0中,原来的NSAttributedString中对应的属性已经变成了NSAttributedStringKey对象,这样的话只需要按照提示来变更就可以了,同样的问题还有

'NSForegroundColorAttributeName' has been renamed to 'NSAttributedStringKey.foregroundColor'

'NSParagraphStyleAttributeName' has been renamed to 'NSAttributedStringKey.paragraphStyle'
'rangeAt' has been renamed to 'range(at:)’

Value of type 'SDWebImageManager' has no member ‘downloadImage'

[站外图片上传中...(image-75fd67-1522133894500)]
在新版本的SDWebImage中,downloadImage方法换到了SDWebImageDownloader对象中了。
[站外图片上传中...(image-d82bde-1522133894500)]

Cannot subscript a value of type '[NSAttributedStringKey : Any]' with an index of type ‘String'

[站外图片上传中...(image-5f24a1-1522133894500)]
在新版本中,字典对应的属性变更,这样的读取会报错,可以修改下面这种读取方式。

参考链接 https://stackoverflow.com/questions/48297878/cannot-subscript-a-value-of-type-nsattributedstringkey-any-with-an-index-o

[站外图片上传中...(image-d54c1-1522133894500)]

定位失效

[站外图片上传中...(image-66a640-1522133894500)]
在新版本中,初始化数据的时候,默认frame是0,所以需要指定frame属性。
[站外图片上传中...(image-73c2ce-1522133894500)]

Navbar遮挡

[站外图片上传中...(image-75963c-1522133894500)]
新版本中,如果隐藏系统Navbar使用自定义的Navbar,Navbar由于NavItem置顶不在留出StatusBar位置,会导致Navbar遮挡StatusBar

解决方案参考 https://zhuanlan.zhihu.com/p/29839893
[站外图片上传中...(image-359978-1522133894500)]

项目地址 https://github.com/HeYming/WeiBo

你可能感兴趣的:(新浪微博4.0版本移植填坑记录)