Questions tagged [cocoa]

Cocoa is Apple's application-development framework for macOS, consisting of Foundation, Application Kit, and Core Data. Use the "cocoa-touch" tag for iOS questions.

Cocoa is Apple's application-development framework for macOS, consisting of Foundation, Application Kit (AppKit) and Core Data.

The Cocoa frameworks consist of libraries, APIs and runtimes that form the development layer for all of macOS.

Related tags

Debugging Techniques

Cocoa programs can be debugged with many techniques and tools, both general and specific to Objective-C, Xcode and macOS.

External Resources

General Resources on SO

Memory Management

More information

39610 questions
14
votes
1 answer

Connecting Menu Items in Document Based Applications

I've already asked a couple questions on this topic, and haven't really received a real answer on how to do it (it actually received the "Tumbleweed Badge" lol). I have a document based application (meaning the Menu.Xib is separate from…
Zakman411
  • 1,764
  • 3
  • 22
  • 45
14
votes
7 answers

UISwitch, something similar for Mac?

I’m sure most of you are familiar with the UISwitch on iOS. Is their any existing project trying to implement something like a UISwitch for macOS and AppKit? If not, where would one start to make one? I see them frequently and can think of so many…
nosedive25
  • 2,477
  • 5
  • 30
  • 45
14
votes
4 answers

How to align a subview to the center of a parent NSView

I'm developing a program in which I am programmatically adding an NSImageView to a custom NSView class. While creating the image-view, I am passing the frame of the parent container. -(NSImageView *)loadNSImage:(NSString *)imageName…
Akshay
  • 1,606
  • 3
  • 17
  • 32
14
votes
3 answers

Subclassing NSView to have a transparent background

I am creating an app where I need to have a transparent NSView with a transparent PNG image inside. The problem is, the NSView I'm drawing has a gray background on it. I have it subclassed (as TransparentRectangleView) but don't know what to put in…
Andrew M
  • 4,208
  • 11
  • 42
  • 67
14
votes
2 answers

How to show a window without stealing focus on macOS?

I was wondering how could spotlight floating with focus, and another window still has focus! I could easy make a window floating over all other window with window?.level = Int(CGWindowLevelForKey(.maximumWindow)),but I cannot let two windows both…
Seven
  • 203
  • 3
  • 7
14
votes
16 answers

How do I convert an NSString from CamelCase to TitleCase, 'playerName' into 'Player Name'?

I'm looking for the easiest way to convert a string from camelback format to Title Case format. How do I change 'playerName' into 'Player Name'?
Evolve
  • 8,939
  • 12
  • 51
  • 63
14
votes
8 answers

Mac OS Cocoa: Draw a simple pixel on a canvas

I wish I would find an answer for this. I have searched and searched and couldn't the right answer. Here is my situation: In a Mac OS Cocoa Application, I want to draw a pixel (actually a few pixels) onto a dedicated area on my application window. I…
Roman
  • 211
  • 1
  • 3
  • 6
14
votes
1 answer

Changing text selection color in NSTextView

I'm trying to write a "highlight" feature on an NSTextView. Currently, everything works great. You select a range of text and the background color of that text changes to yellow. However, while it's still selected, the background is that standard…
Dexter
  • 5,666
  • 6
  • 33
  • 45
14
votes
3 answers

What are common pitfalls of timestamp based syncing?

I am implementing my first syncing code. In my case I will have 2 types of iOS clients per user that will sync records to a server using a lastSyncTimestamp, a 64 bit integer representing the Unix epoch in milliseconds of the last sync. Records…
John Wright
  • 2,418
  • 4
  • 29
  • 34
14
votes
2 answers

How to disable Macbook Pro from switching to a high performance graphics card in Cocoa?

All 2010 Macbook Pros come with two graphics cards — a low-performance built-in Intel HD one and a high-performance discrete NVIDIA one — and it switches between them on the fly depending on the needs of the running applications. I have a simple…
Alexey Blinov
  • 1,684
  • 3
  • 17
  • 25
14
votes
1 answer

Get Image from CALayer or NSView (swift 3)

I was looking for a way to render a CALayer or NSView and get NSImage back. I have a custom class, which is a subclass of NSView. At the beginning I simply make a gradient layer to cover NSView. class ContentView: NSView { override func draw(_…
Alexei
  • 511
  • 1
  • 10
  • 22
14
votes
4 answers

NSRunningApplication 'terminated' not Observable

I'm building a program that launches another program and is then supposed to monitor it, and take action if it terminates. When the application is launched, I can get an instance of NSRunningApplication from NSWorkspace. Now, the documentation…
Iain Delaney
  • 562
  • 4
  • 17
14
votes
2 answers

Best Logger for cocoa

Can anyone recommend me a good logger for cocoa, something that should be in par with log4j. I've been developing this app in cocoa & as the source code is growing I find my self craving for a logger. I've googled a bit, have found a few options but…
Asad Khan
  • 11,469
  • 13
  • 44
  • 59
14
votes
4 answers

Swift weak lazy variable won't compile

To demonstrate this problem, I made a vanilla Cocoa project. Here is the AppDelegate.swift: import Cocoa @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate { weak lazy var isGood : NSNumber? = { return true }() …
LShi
  • 1,500
  • 16
  • 29
14
votes
2 answers

By default, is DispatchQueue .serial or .concurrent?

That's the question, straight-forward as that. let serial = DispatchQueue(label: "serial", attributes: .serial) let concurrent = DispatchQueue(label: "concurrent", attributes: .concurrent) let q = DispatchQueue(label: "q") I see no property I can…
SimplGy
  • 20,079
  • 15
  • 107
  • 144