简体   繁体   中英

OS X application by code swift

I am coming from a background of a iOS engineer where I was not using Storyboards or XIBs at all. Now I have to make a Max OS X app and there are couple of issues.

Is it worth doing it all by code? (or is it different to iOS in some fundamental ways that it should not be tried)

How to do it by code?

The approach I was trying is

func applicationDidFinishLaunching(aNotification: NSNotification) {
    var window = NSWindow(contentRect: self.articleViewController.view.frame, styleMask: NSBorderlessWindowMask, backing: NSBackingStoreType.Buffered, defer: false)
    window.contentViewController = self.articleViewController
    window.makeKeyAndOrderFront(window)
}

But the app delegate doesn't get called. Then I found out that I need to create MainMenu.XIB(realy dont want to do it), but ok. Done that added App delegate as delegate on interface builder, but it still doesn't get called.

在此处输入图片说明 I have @NSApplicationMain on the top, presumably that should call app delegate first.

This is an opinion-based question.

My opinion is that creating UI with code is folly. It takes a lot more work, it is harder to read, and it is harder to maintain.

Most importantly, Apple's tools are built around using interface builder. They started out using XIB files, and are now moving to using storyboards.

Some things simply won't work unless you use XIBs or storyboards, and other things won't work if you don't use Storyboards. (eg static table views and cell templates in iOS)

If you want to swim against the tide and do everything in code, have fun with that.

In my opinion it is not worth doing it all in code. Use XIB files. Thats way easier. This is a simple tutorial to start with

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM