---
title: "Dynamically creating Cocoa window:"  
description: "Dynamically creating Cocoa window:"  
author: "Anonymous User"  
published: 2015-10-12  
updated: 2015-10-12  
canonical: https://www.mindstick.com/forum/33506/dynamically-creating-cocoa-window  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 2 minutes  

---

# Dynamically creating Cocoa window:

I want to creae Cocoa [window](https://www.mindstick.com/forum/161285/how-does-the-window-console-object-work-in-javascript) at [runtime](https://www.mindstick.com/articles/52/creating-timer-at-runtime-in-c-sharp-dot-net), I was [trying](https://answers.mindstick.com/qa/93698/6-mistakes-couples-are-trying-to-save-money) to generate [dynamic](https://www.mindstick.com/blog/11080/features-of-java-dynamic-complied-and-interpreted) window but it is not working,\
this is my code:

```
NSRect myFrame = NSMakeRect(0, 0, 100, 100);NSUInteger mask = NSBorderlessWindowMask;NSRect myRect = [NSWindow contentRectForFrameRect:myFrame mask:mask];NSWindow * myWindow =  [[NSWindow alloc] initWithContentRect:myRect                       mask:mask backing: NSBackingStoreRetained                       defer:false];[myWindow setBackgroundColor:[NSColor blueColor]];[myWindow display];
```

My code is generating [error](https://yourviews.mindstick.com/view/88527/fixing-quickbooks-error-4120-reinstalling-vs-repairing) and I am new in iOS so I [am unable](https://answers.mindstick.com/qa/95314/how-do-i-access-a-group-link-in-telegram-if-i-am-unable-to-access-the-link) to [solve this problem](https://answers.mindstick.com/qa/94681/my-google-assistant-shows-completely-different-search-results-from-what-i-ask-how-can-i-solve-this-problem),\
please [anyone help me](https://www.mindstick.com/forum/331/can-anyone-help-me-out-how-to-use-session-concept).\

## Replies

### Reply by Tarun Kumar

The [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) is that you don't want to call display, you want to call either makeKeyAndOrderFront or orderFront depending on whether or not you want the window to become the key myWindow. You should also probably use NSBackingStoreBuffered.\
This code will create your borderless, green window at the bottom left of the screen:

```
NSRect myFrame = NSMakeRect(0, 0, 100, 100);NSWindow* myWindow  = [[[NSWindow alloc] initWithContentRect:myFrame                    mask:NSBorderlessWindowMask                    backing:NSBackingStoreBuffered                    defer:NO] autorelease];[myWindow setBackgroundColor:[NSColor greenColor]];[myWindow makeKeyAndOrderFront:NSApp];
```

- Don't forget to assign myWindow to a strong/retaining property!\
- Under ARC, not doing so will cause it to disappear immediately;\
- without ARC, the window will be leaked.

You can make the sender for makeKeyAndOrderFront or orderFront whatever is appropriate for your situation.


---

Original Source: https://www.mindstick.com/forum/33506/dynamically-creating-cocoa-window

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
