📜 ⬆️ ⬇️

UIAppearance was not so simple

The UIAppearance protocol appeared in iOS 5 in 2011, in those distant times when Instagram did not have an Android application, and the serial Ned Stark was not yet cut off.


What about eddard

Maester sent me a crow with the news that at the time of release of iOS 5 - already chopped off. But in order not to spoil the red wedding or something else, perhaps, I will leave everything as it is.


There is enough information, tutorials, articles on this topic, every iOS developer who is a beginner knows how and why to use it, so this article is not about that. I would like to reflect on what is wrong with him, in my opinion, and why Apple is not paying attention to it.


As a small introductory excerpt from the documentation , which has always been, is and should be the main trusted source of information.


There is a window for sending proxy.

To comply with the UIAppearanceContainer protocol, it must be marked with UI_APPEARANCE_SELECTOR

For myself, I understand it this way: if you want to change the default appearance for all objects of the class implementing the UIAppearance , check whether the property is marked with UI_APPEARANCE_SELECTOR and go ahead. Accordingly, if the property is not UI_APPEARANCE_SELECTOR , then this will not work.


But “failing” does not mean “you can’t try,” so I suggest everyone to conduct a simple experiment: open the first project and add the following line to the application:didFinishLaunchingWithOptions: method:


 UIView.appearance().isHidden = true 

Estimate what happens and run.


I, as a bore, would expect possible options:



But no, everything, including the main application window, becomes hidden. On the one hand, it is even logical - what is written is done. But on the other hand, it looks like undocumented behavior and, as it seems to me, such a rather big hole.


I could still accept the fact that such tricks could be turned only with those properties that affect the appearance, but this can be done with all properties !


For example, adding to the code that other projects use as a third-party library, this is the line that is sometimes called at a random time:


 UITableView.appearance().delegate = nil 

You can reset all delegates to all tables that appear on the screen after executing this code.


Developers will have a lot of fun trying to understand what happened! Surely, you can come up with something even more fun!


I really hope that such things did not go unnoticed by Apple (information on this subject, however, I did not find), and such tricks are revealed somewhere during the automatic assembly check in AppstoreConnect. But I don’t want to check, to be honest.


Such things, guys. I would be glad to discuss if the topic is interesting to someone.


PS Give me back my 2011!


')

Source: https://habr.com/ru/post/453126/


All Articles