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
363
votes
12 answers

Best way to define private methods for a class in Objective-C

I just started programming Objective-C and, having a background in Java, wonder how people writing Objective-C programs deal with private methods. I understand there may be several conventions and habits and think about this question as an…
Yurii Soldak
  • 1,458
  • 4
  • 19
  • 24
355
votes
6 answers

Difference between objectForKey and valueForKey?

What is the difference between objectForKey and valueForKey? I looked both up in the documentation and they seemed the same to me.
Devoted
  • 177,705
  • 43
  • 90
  • 110
346
votes
33 answers

What are best practices that you use when writing Objective-C and Cocoa?

I know about the HIG (which is quite handy!), but what programming practices do you use when writing Objective-C, and more specifically when using Cocoa (or CocoaTouch).
pixel
  • 5,298
  • 8
  • 35
  • 32
341
votes
6 answers

How do I use NSTimer?

How do I use an NSTimer? Can anyone give me step by step instructions?
lab12
  • 6,400
  • 21
  • 68
  • 106
338
votes
89 answers

Hidden Features of Xcode

With a huge influx of newbies to Xcode, I'm sure there are lots of Xcode tips and tricks to be shared. What are yours?
schwa
  • 11,962
  • 14
  • 43
  • 54
336
votes
10 answers

NSString property: copy or retain?

Let's say I have a class called SomeClass with a string property name: @interface SomeClass : NSObject { NSString* name; } @property (nonatomic, retain) NSString* name; @end I understand that name may be assigned a NSMutableString in which…
Debajit
  • 46,327
  • 33
  • 91
  • 100
332
votes
17 answers

What is the best way to unit test Objective-C code?

What frameworks exist to unit test Objective-C code? I would like a framework that integrates nicely with Apple Xcode.
Kim
  • 4,593
  • 5
  • 21
  • 18
316
votes
4 answers

Core Data vs SQLite 3

I am already quite familiar with relational databases and have used SQLite (and other databases) in the past. However, Core Data has a certain allure, so I am considering spending some time to learn it for use in my next application. Is there much…
Jason Medeiros
  • 5,358
  • 3
  • 25
  • 18
304
votes
7 answers

How do you print out a stack trace to the console/log in Cocoa?

I'd like to log the call trace during certain points, like failed assertions, or uncaught exceptions.
robottobor
  • 11,595
  • 11
  • 39
  • 37
283
votes
3 answers

What does "@private" mean in Objective-C?

What does @private mean in Objective-C?
user100051
268
votes
12 answers

CSS Printing: Avoiding cut-in-half DIVs between pages?

I'm writing a plug-in for a piece of software that takes a big collection of items and pops them into HTML in a WebView in Cocoa (which uses WebKit as its renderer, so basically you can assume this HTML file is being opened in Safari). The DIVs it…
joeylange
  • 2,873
  • 2
  • 17
  • 7
266
votes
9 answers

How to update a single pod without touching other dependencies

I understand that the following command will update a single pod: pod update . However this also updates the dependencies of other pods (pods that were not included in the update command) that you have previously installed. Is there a way…
ken
  • 3,897
  • 3
  • 22
  • 28
261
votes
46 answers

"Unknown class in Interface Builder file" error at runtime

Even though Interface Builder is aware of a MyClass, I get an error when starting the application. This happens when MyClass is part of a library, and does not happen if I compile the class directly in the application target.
jhoule
  • 2,466
  • 3
  • 17
  • 12
259
votes
3 answers

Objective-C: Extract filename from path string

When I have NSString with /Users/user/Projects/thefile.ext I want to extract thefile with Objective-C methods. What is the easiest way to do that?
Anton
  • 3,352
  • 3
  • 23
  • 15
246
votes
33 answers

Delete/Reset all entries in Core Data?

Do you know of any way to delete all of the entries stored in Core Data? My schema should stay the same; I just want to reset it to blank. Edit I'm looking to do this programmatically so that a user can essentially hit a reset button.
Michael Grinich
  • 4,770
  • 8
  • 29
  • 30