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
176
votes
6 answers

How to create a Menubar application for Mac

EDIT: This is a nice ready-made menubar application here (github source) by this answer. I was wondering how to make a menubar application, what are the requirements for that to do so? I saw a simple application for the menubar was to open links…
MacMac
  • 34,294
  • 55
  • 151
  • 222
173
votes
10 answers

Regular expressions in an Objective-C Cocoa application

Initial Googling indicates that there's no built-in way to do regular expressions in an Objective-C Cocoa application. So four questions: Is that really true? Are you kidding me? Ok, then is there a nice open-source library you recommend? What are…
dreeves
  • 26,430
  • 45
  • 154
  • 229
162
votes
7 answers

What's the difference between "bundle display name" and "bundle name" in cocoa application's info plist

Here is a good question: Bundle Name, Executable Name, Product Name...anything else? but I just wonder about the difference between "bundle display name" and "bundle name" in cocoa application's info plist.
xhan
  • 6,057
  • 4
  • 33
  • 47
159
votes
9 answers

How does an underscore in front of a variable in a cocoa objective-c class work?

I've seen in a few iPhone examples that attributes have used an underscore _ in front of the variable. Does anyone know what this means? Or how it works? An interface file I'm using looks like: @interface MissionCell : UITableViewCell { Mission…
Atma
  • 29,141
  • 56
  • 198
  • 299
154
votes
20 answers

Generate a random alphanumeric string in Cocoa

I want to call a method, pass it the length and have it generate a random alphanumeric string. Are there any utility libraries out there that may have a bunch of these types of functions?
Ward
  • 3,318
  • 3
  • 30
  • 50
154
votes
4 answers

Objective-C - Remove last character from string

In Objective-C for iOS, how would I remove the last character of a string using a button action?
Omar
  • 2,155
  • 4
  • 24
  • 38
151
votes
9 answers

What does the property "Nonatomic" mean?

What does "nonatomic" mean in this code? @property(nonatomic, retain) UITextField *theUsersName; What is the difference between atomic and nonatomic? Thanks
user100051
150
votes
7 answers

How do you set the text in an NSTextField?

I'm trying to set the text in an NSTextField, but the -setStringValue: and -setTitleWithMnemonic: methods are not working. Any ideas?
Alexsander Akers
  • 15,967
  • 12
  • 58
  • 83
146
votes
9 answers

NSString tokenize in Objective-C

What is the best way to tokenize/split a NSString in Objective-C?
ggarber
144
votes
7 answers

Fix warning "Capturing [an object] strongly in this block is likely to lead to a retain cycle" in ARC-enabled code

In ARC enabled code, how to fix a warning about a potential retain cycle, when using a block-based API? The warning: Capturing 'request' strongly in this block is likely to lead to a retain cycle produced by this snippet of code: ASIHTTPRequest…
Guillaume
  • 21,685
  • 6
  • 63
  • 95
143
votes
11 answers

How can I tell if an object has a key value observer attached

If you tell an Objective-C object to removeObservers: for a key path and that key path has not been registered, it cracks a sad, like: Cannot remove an observer for the key path "theKeyPath" from because it is…
Aran Mulholland
  • 23,555
  • 29
  • 141
  • 228
141
votes
4 answers

NSInvocation for Dummies?

How exactly does NSInvocation work? Is there a good introduction? I’m specifically having issues understanding how the following code (from Cocoa Programming for Mac OS X, 3rd Edition) works, but then also be able to apply the concepts independently…
John Rudy
  • 37,282
  • 14
  • 64
  • 100
140
votes
3 answers

NSLog/printf specifier for NSInteger?

A NSInteger is 32 bits on 32-bit platforms, and 64 bits on 64-bit platforms. Is there a NSLog specifier that always matches the size of NSInteger? Setup Xcode 3.2.5 llvm 1.6 compiler (this is important; gcc doesn't do…
Steven Fisher
  • 44,462
  • 20
  • 138
  • 192
139
votes
10 answers

Getting a list of files in a directory with a glob

For some crazy reason I can't find a way to get a list of files with a glob for a given directory. I'm currently stuck with something along the lines of: NSString *bundleRoot = [[NSBundle mainBundle] bundlePath]; NSArray *dirContents =…
sammich
  • 335
  • 5
  • 13
  • 19
138
votes
18 answers

How to manually create icns files using iconutil?

When I'm validating my app I get this error: the application bundle does not contain an icon in ICNS format, containing both a 512x512 and a 512x512@2x image. I use to make the icns icons with Img2icns app and until today it always worked…
Blue
  • 2,300
  • 3
  • 21
  • 32