21

I've noticed that all applications on OS X seem to save the size you set it at. The next time you open it it's typically in the same position and size.

I'm making an app and I've noticed that after resizing, if I launch the application again it's just the size of what I've set in Xcode 4's IB and not the size that I resized it to on launch.

Do I have to manually save the window size each time its changed? Or is there an easier way to do this through IB? (My window does have a minimum size set if that changes anything.)

aroooo
  • 4,726
  • 8
  • 47
  • 81

4 Answers4

34

Apple makes it easy. In interface builder, for your window, just type in a unique name in the Autosave field and it will save it under that name in the global user defaults. E.G.

enter image description here

Vervious
  • 5,559
  • 3
  • 38
  • 57
5

When you select your main window in the Interface Builder, there should be a property called Autosave in the attributes inspector. Put any name in there does the trick for me.

Jimmy Luong
  • 1,109
  • 1
  • 8
  • 16
5

After setting the Autosave name in IB I could see that my window's frame was being saved to its preferences file, but still the auto restore would not work. Then I remembered to uncheck the Close windows when quitting an app checkbox in the System Preferences under the General settings, and the window position restored as expected.

Alex Popadich
  • 141
  • 2
  • 4
3

If you did not use IB to create your window, you can set this property in Swift using:

setFrameAutosaveName(_ name: NSWindow.FrameAutosaveName)

(the frameAutosaveName property is get only)

For example:

windowController.window?.setFrameAutosaveName("appWindow")
Ryan H
  • 1,656
  • 14
  • 15