Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试创建一个自定义警报视图,以检查条件是否为真,如果是,它会自行构建并将自身附加到窗口。但是,如果这个条件不成立,我只想让视图自行释放,最好是在init方法中。实现这一目标的最佳方法是什么?
init
好吧,最好在编码中遵循 SOLID 原则。
奇点是一件很重要的事情。一个函数应该做一件事情,而不是很多依赖。
所以保留视图只是为了显示自定义警报。并且显示的检查必须在外部完成,这样
//Please note this is the algorithm not the exact code in Obj-C. if(condition==True) { //Display customView } else { //Do nothing }