Xcode 10 beta2: Cannot invoke initializer for type 'UIView' with no arguments

最后都变了- 提交于 2019-12-23 09:26:44

问题


I have downloaded Xcode 10 beta2 and rebuild my project, codes such as:

let someView = UIView()

come up with the following error:

Cannot invoke initializer for type 'UIView' with no arguments

Pretty strange. Has anybody encountered those building errors when using Xcode 10 beta2?


回答1:


For me it was reasoned by extending NSObjectProtocol:

extension NSObjectProtocol where Self: UIView

I fixed it by replacing NSObjectProtocol to any other protocol that UIView conforms. In my case it was UIAppearance:

extension UIAppearance where Self: UIView



回答2:


try this

let someView = UIView(frame: CGRect.zero)

it works for me




回答3:


Just add the "frame" argument: UIView(frame: CGRect.zero) (or whatever you need it to be)

In my code I set up the Views like this and later I add constraints (which basically override frame parameters).

The same works for UIView, UILabel, UIScrollView and others... For UIButtons, add the "type" argument instead: UIButton(type: UIButtonType.custom)




回答4:


After hours of debugging I have finally found the problem.

I use a pod SwiftTheme, after upgrading it to a new version those errors have gone.

See this commit.



来源:https://stackoverflow.com/questions/51124370/xcode-10-beta2-cannot-invoke-initializer-for-type-uiview-with-no-arguments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!