Xcode 4.2 Template Changes - UIApplication & MainWindow.xib

Background:. Prior to Xcode 4.2, new projects created using any of the templates will contain MainWindow.xib and therefore pass nil as the fourth argument to UIApplicationMain (). Starting with Xcode 4.2, all templates instantiate the application delegate by passing the class string as the fourth argument and do not build the application window in xib.

It is trivial to make this setting in 4.2, and, of course, it works as expected: create xib for the File Owner parameter for UIApplication and connect the delegate, specify it in Info.plist, nil the fourth argument in main ().

Question: Why does Apple encourage the creation of an instance of a delegate application and the creation of a UIWindow in code instead of the "old way"? What are the benefits?

Considerations: I would expect this new template behavior if you decide to use the storyboard as a way to control the user interface, but if you uncheck the Use storyboards box, I would expect the old pass-nil -and-use-MainWindow.xib.

This question has been asked on a circular path here , but the answers are a bit subtle in the discussion.

+6
source share
1 answer

You ask why Apple is doing something? There can be no definitive answer if Apple did not speak out explicitly, which they did not.

Personally, I find the new approach more elegant, transparent and bulletproof. As you rightly say, in the old approach, the main thread was loaded automatically by the runtime in response to the Info.plist parameter, and everything else that happened was done via nib, in particular, creating an instance of the application delegate and the window and the related wiring (delegate the application must be delegated to the application, the window must be made in the application delegation window), except that we return to the code in the application delegate for the final presentation of the interface.

It was hard to understand; it took me a lot of verbal words to describe it in my book. It was also easy to break. Pink needs to know the class name of the application delegate, so if you don't like these funny long names that were created by default, you can easily corrupt everything when you change them.

Now, however, the application delegate is simply called App Delegate and is created in the code using UIApplicationMain (), as you say correctly; and everything else is also executed in the code as a direct follow-up: the application delegate is created and makeFinishLaunching is called, after which we create a window in the code, assign it to our property in the code, load nib, if it is in the code, set the rootViewController window to the code and show the interface in code as before.

Thus, self-tuning directly opens for viewing, because this is all the code. This facilitates understanding and modification without breaking anything. It’s almost as if the template designer previously simply showed how many things could be done magically and automatically behind the scenes; now everything happens openly, openly.

+7
source

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


All Articles