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
1403
votes
39 answers

How can I check for an active Internet connection on iOS or macOS?

I would like to check to see if I have an Internet connection on iOS using the Cocoa Touch libraries or on macOS using the Cocoa libraries. I came up with a way to do this using an NSURL. The way I did it seems a bit unreliable (because even Google…
Brock Woolf
  • 46,656
  • 50
  • 121
  • 144
1312
votes
81 answers

Xcode - How to fix 'NSUnknownKeyException', Reason: "… this class is not key value coding-compliant for the key X" error?

I'm trying to link a UILabel with an IBOutlet created in my class. My application is crashing with the following error" *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x6e36ae0>…
Guillaume Dubois
  • 2,003
  • 3
  • 13
  • 4
1046
votes
14 answers

Constants in Objective-C

I'm developing a Cocoa application, and I'm using constant NSStrings as ways to store key names for my preferences. I understand this is a good idea because it allows easy changing of keys if necessary. Plus, it's the whole 'separate your data from…
Allyn
  • 20,271
  • 16
  • 57
  • 68
772
votes
20 answers

How do I create delegates in Objective-C?

I know how delegates work, and I know how I can use them. But how do I create them?
Andy Jacobs
  • 15,187
  • 13
  • 60
  • 91
718
votes
16 answers

@class vs. #import

It is to my understanding that one should use a forward-class declaration in the event ClassA needs to include a ClassB header, and ClassB needs to include a ClassA header to avoid any circular inclusions. I also understand that an #import is a…
Coocoo4Cocoa
  • 48,756
  • 50
  • 150
  • 175
716
votes
10 answers

Cocoa Autolayout: content hugging vs content compression resistance priority

I can't find a clear answer on Apple documentation regarding Cocoa Autolayout about the difference between content hugging and compression resistance. Can somebody explain their usages and difference ?
dmitrynikolaev
  • 8,994
  • 4
  • 30
  • 45
648
votes
9 answers

What does the NS prefix mean?

Many classes in Cocoa/Cocoa Touch have the NS prefix. What does it mean?
Martin08
  • 20,990
  • 22
  • 84
  • 93
631
votes
13 answers

Cocoa: What's the difference between the frame and the bounds?

UIView and its subclasses all have the properties frame and bounds. What's the difference?
mk12
  • 25,873
  • 32
  • 98
  • 137
570
votes
8 answers

@synthesize vs @dynamic, what are the differences?

What are the differences between implementing a @property with @dynamic or @synthesize?
nico
  • 9,668
  • 8
  • 26
  • 28
465
votes
8 answers

How do I iterate over an NSArray?

I'm looking for the standard idiom to iterate over an NSArray. My code needs to be suitable for OS X 10.4+.
Steve McLeod
  • 51,737
  • 47
  • 128
  • 184
451
votes
13 answers

How to print out the method name and line number and conditionally disable NSLog?

I'm doing a presentation on debugging in Xcode and would like to get more information on using NSLog efficiently. In particular, I have two questions: is there a way to easily NSLog the current method's name / line number? is there a way to…
rein
  • 32,967
  • 23
  • 82
  • 106
425
votes
13 answers

throwing an exception in objective-c/cocoa

What's the best way to throw an exception in objective-c/cocoa?
Steph Thirion
  • 9,313
  • 9
  • 50
  • 58
417
votes
9 answers

Is It Possible to NSLog C Structs (Like CGRect or CGPoint)?

I want to be able to debug C structures without having to explicitly type every property that they consist of. i.e. I want to be able to do something like this: CGPoint cgPoint = CGPointMake(0,0); NSLog(@"%@",cgPoint); Obviously the '%@' won't…
mazniak
  • 5,849
  • 6
  • 28
  • 23
393
votes
9 answers

How do I convert NSMutableArray to NSArray?

How do I convert NSMutableArray to NSArray in objective-c?
marcy
  • 4,213
  • 3
  • 23
  • 14
363
votes
25 answers

Exception thrown in NSOrderedSet generated accessors

On my Lion app, I have this data model: The relationship subitems inside Item is ordered. Xcode 4.1 (build 4B110) has created for me the file Item.h, Item.m, SubItem.h and SubItem.h. Here is the content (autogenerated) of Item.h: #import…
Dev
  • 7,027
  • 6
  • 37
  • 65
1
2 3
99 100