is there a way to shorten prefences list in swift
is there a way to shorten prefences list in swift
is there a way to set this in one line
by example
appwindow(setContentSize(NSSize(width: 400, height: 23),titlebarAppearsTransparent = true) ect
rather than having to spell them one by one
appWindow.setContentSize(NSSize(width: 400, height: 23))
appWindow.titlebarAppearsTransparent = true
appWindow.isMovableByWindowBackground = true
appWindow.backgroundColor = NSColor.white //Maybe have it gray instead so we can remove this?
appWindow.setFrameAutosaveName(NSWindow.FrameAutosaveName(rawValue: "myGoodGoodApp"))
appWindow.makeKeyAndOrderFront(nil)
appWindow.contentView?.addSubview(gunTrigger)
Why do you wish to put it all on one line? It's must easier to read, debug, and change the code when it is on separate lines.
– rmaddy
Sep 5 '18 at 13:22
@maddy it just seem professial app wouldnt have it this way i cant recal seeing pro apps who do it this way
– jessyjannis
Sep 5 '18 at 13:24
@ValW a function like a forEach with $0 ?
– jessyjannis
Sep 5 '18 at 13:25
Btw putting it in one line seems way unprofessional then that way. professional != complicated. Easy to read code is mostly good code.
– ValW
Sep 5 '18 at 13:28
1 Answer
1
You can use an immediately executed closure to give yourself a scope in which you can have a short variable name, while allowing you to preserve a better, longer name in the rest of the usage. It's a particularly useful technique for value types, as this allows you to keep the mutability constrained to the closure.
let appWindow: NSWindow =
let w = NSWindow()
w.setContentSize(NSSize(width: 400, height: 23))
w.titlebarAppearsTransparent = true
w.isMovableByWindowBackground = true
w.backgroundColor = NSColor.white //Maybe have it gray instead so we can remove this?
w.setFrameAutosaveName(NSWindow.FrameAutosaveName(rawValue: "myGoodGoodApp"))
w.makeKeyAndOrderFront(nil)
w.contentView?.addSubview(gunTrigger)
return w
()
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Nop there isn't, the only thing you could do is make a function
– ValW
Sep 5 '18 at 13:22