All Questions
Tagged with macos objective-c
11,398
questions
338
votes
89
answers
241k
views
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?
241
votes
25
answers
109k
views
Easy way to see saved NSUserDefaults?
Is there a way to see what's been saved to NSUserDefaults directly? I'd like to see if my data saved correctly.
239
votes
5
answers
42k
views
What kind of leaks does automatic reference counting in Objective-C not prevent or minimize?
In the Mac and iOS platforms, memory leaks are often caused by unreleased pointers. Traditionally, it has always been of utmost importance to check your allocs, copies and retains to make sure each ...
212
votes
29
answers
536k
views
Xcode build failure "Undefined symbols for architecture x86_64"
An Xcode beginner's question:
It is my first experience with Xcode 4.6.3.
I am trying to write a very simple console program, that searches for paired BT devices and prints them to an NSLog.
It ...
211
votes
12
answers
136k
views
Execute a terminal command from a Cocoa app
How can I execute a terminal command (like grep) from my Objective-C Cocoa application?
178
votes
13
answers
43k
views
What is the best way to solve an Objective-C namespace collision?
Objective-C has no namespaces; it's much like C, everything is within one global namespace. Common practice is to prefix classes with initials, e.g. if you are working at IBM, you could prefix them ...
170
votes
7
answers
107k
views
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 ...
163
votes
18
answers
127k
views
Best way to change the background color for an NSView
I'm looking for the best way to change the backgroundColor of an NSView. I'd also like to be able to set the appropriate alpha mask for the NSView. Something like:
myView.backgroundColor = [NSColor ...
150
votes
21
answers
81k
views
Xcode 5: Code signing entitlement errors
I've build a new application which is going to support IOS 7. I got the new XCode 5 GM and tried to sign my apps using my fresh provisioning profile and distribution certificate, but i'm having ...
146
votes
10
answers
79k
views
Suppressing deprecated warnings in Xcode
With all the SDKs floating around, it's handy to be able to build for multiple SDKs and platforms. However, bouncing from 3.2 to 3.0 and even occasionally 2.x, I frequently get deprecated warnings ...
130
votes
4
answers
29k
views
What makes a keychain item unique (in iOS)?
My question concerns keychains in iOS (iPhone, iPad, ...). I think (but am not sure) that the implementation of keychains under Mac OS X raises the same question with the same answer.
iOS provides ...
124
votes
2
answers
69k
views
Convert NSURL to local file path
I have an NSURL that looks like this:
file://localhost/Users/myuser/myfile.txt
Is there a standard function to convert it to a local file path looking like this:
/Users/myuser/myfile.txt
117
votes
10
answers
78k
views
How can I convert from degrees to radians?
I am trying to convert this Obj-C code to Swift code but I don't know what the equivalent of this code should be ?
#define DEGREES_TO_RADIANS(degrees)((M_PI * degrees)/180)
I googled and found this
...
116
votes
9
answers
74k
views
Swift - which types to use? NSString or String
With the introduction of Swift I've been trying to get my head round the new language
I'm an iOS developer and would use types such as NSString, NSInteger, NSDictionary in an application. I've ...
102
votes
9
answers
35k
views
Xcode linker error: file too small for architecture x86_64
I'm developing an application in Xcode.
When I try to build, this error comes up:
ld: in /Users/theodore/Library/Developer/Xcode/DerivedData/Tower-bkpdifuqssebjdgurzmtirbxejnn/Build/Intermediates/...
92
votes
10
answers
41k
views
View-based NSTableView with rows that have dynamic heights
I have an application with a view-based NSTableView in it. Inside this table view, I have rows that have cells that have content consisting of a multi-row NSTextField with word-wrap enabled. ...
86
votes
4
answers
116k
views
Objective C - Assign, Copy, Retain
I'm new to Objective C. I have basic knowledge in C, including the concept of pointers. I have two basic questions:
Can someone explain the difference between assign,copy, and retain with some ...
84
votes
5
answers
40k
views
Where is a Mac Application's NSUserDefaults Data Stored?
I am using NSUserDefaults to store some data in my application.
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setObject:@"dummy string" forKey:@"lastValue"];
[prefs ...
84
votes
4
answers
44k
views
ARC - The meaning of __unsafe_unretained?
Just want to make sure that I got it right:
Do I need to __unsafe_unretain objects that I don't own?
If an object is __unsafe_unretained Do I need to use assign in the @property? Does that mean that ...
83
votes
2
answers
15k
views
Cannot use respondsToSelector using ARC on Mac
When I call respondsToSelector in an ARC environment, I get the following error message Automatic Reference Counting Issue No known instance method for selector respondsToSelector:
This is the header
...
80
votes
3
answers
37k
views
What is the strong property attribute
I am using the Xcode beta for developers, and am noticing some subtle differences. Among them is a new attribute for declared properties.
@property(strong)IBOutlet NSArrayController *arrayControl;
...
79
votes
11
answers
56k
views
NSArray Equivalent of Map
Given an NSArray of NSDictionary objects (containing similar objects and keys) is it possible to write perform a map to an array of specified key? For example, in Ruby it can be done with:
array.map(&...
76
votes
11
answers
103k
views
Rounding numbers in Objective-C
I'm trying to do some number rounding and conversion to a string to enhance the output in an Objective-C program.
I have a float value that I'd like to round to the nearest .5 and then use it to set ...
76
votes
8
answers
39k
views
Enabling tabs in xcode? Or lessening the pain of not having them?
I am currently using xcode and I find it's lack of tabs quite disturbing.
I currently use command-shift-d to search through all the files, or ctrl-1 to open the history of files that were recently ...
75
votes
1
answer
17k
views
Xcode Project Format: what are the differences between 3.1, 3.2, 6.3 and 8.0?
When I open a project in Xcode 9 (or previous versions) and check the File Inspector, there's a section called Project Document, with a combo box named Project Format.
The available options (in Xcode ...
73
votes
1
answer
11k
views
Do you need to create an NSAutoreleasePool within a block in GCD?
Normally, if you spawn a background thread or run an NSOperation on an NSOperationQueue you need to create an NSAutoreleasePool for that thread or operation because none exists by default.
Does the ...
72
votes
11
answers
32k
views
Turn off sound in iPhone Simulator
Is there an option to turn off the sound on the iPhone Simulator?
Or to adjust the volume?
70
votes
5
answers
41k
views
Block implicitly retains 'self'; explicitly mention 'self' to indicate this is intended behavior
Given the following:
- (void) someMethod
{
dispatch_async(dispatch_get_main_queue(), ^{
myTimer = [NSTimer scheduledTimerWithTimeInterval: 60
...
69
votes
10
answers
68k
views
How to get the file size given a path?
I have a path to file contained in an NSString. Is there a method to get its file size?
69
votes
2
answers
3k
views
tgmath.h doesn't work if modules are enabled
I looked into using tgmath.h to deal with the CGFloat typedef float/double mess when dealing with arm64.
This answer has a pretty good description of how to use it, except that it didn't work at all ...
68
votes
12
answers
22k
views
Cocoa-Touch: How do I see if two NSDates are in the same day?
I need to know if two NSDate instances are both from the same day.
Is there an easier/better way to do it than getting the NSDateComponents and comparing day/month/year?
68
votes
5
answers
109k
views
List of all users and groups
I'm trying to get a list of all users and all groups on Mac OS X 10.5+. How can I do this?
For example, the list of all users on my machine should return:
_amavisd, _appowner, _appserver, _ard, ...
65
votes
6
answers
58k
views
Class Foo is implemented in both MyApp and MyAppTestCase. One of the two will be used. Which one is undefined
Recently I started Unit testing my application. This project (in Xcode4) was created without a unit test bundle so I had to set it up.
I have followed the steps from here: http://cocoawithlove.com/...
60
votes
6
answers
39k
views
Sample code for creating a NSTextField "label"?
In my desktop Mac OS X app, I'd like to programatically create a NSTextField "label" which has the same behavior and properties as a typical label created in Interface Builder.
I usually use (and ...
58
votes
2
answers
23k
views
Send notification to Mountain lion notification center
Can someone give an example of sending a test notification from a Cocoa app to Notifications Center? eg. when I click on an NSButton
58
votes
23
answers
39k
views
Xcode: Could not inspect the application package
I am running Xcode 6 and iOS 8 GM. Every other time I run my app I get this message from Xcode:
"Could not inspect the application package"
So I can run and build, I will get the message. I run ...
58
votes
1
answer
4k
views
Setting Notifications on Characteristic results in Invalid Handle error
Using CoreBluetooth I want to send data from iPhone to Mac. For this I wrote code like iPhone as 'Peripheral' and Mac as 'Central'.
It works perfectly, but sometimes it disconnects directly and then ...
52
votes
3
answers
14k
views
Why are umbrella frameworks discouraged? [closed]
I want to distribute Framework A. Framework A depends on Framework B. I want a user of my framework to only need to include Framework A, but still have programmatic access to Framework B.
Apple does ...
50
votes
5
answers
22k
views
How do I quit a mac application programmatically?
I need to add a quit-button to my application that runs from the menubar in mac.
How do I programmatically quit an application in mac?
50
votes
8
answers
30k
views
How to Write OS X Finder plugin
I'm looking for a guide or sample code for writing Mac OS X Finder plugins? It would like to know how to do some simple actions:
adding image overlayers to icons
adding context menu items
listen to ...
48
votes
6
answers
16k
views
Callbacks When an NSScrollView is Scrolled?
I'm making a Mac app which needs to know when the user is scrolling the NSScrollView, however, I can't find any methods like UIScrollView, which has the following delegate methods:
– ...
47
votes
9
answers
95k
views
Target pattern contains no '%'. Makefile
I have searched this problem in google, but still don't have some way to resolve a problem. I have 2 Makefiles: One as example and one as my file.
Example:
BINDDIR=/src/binding
XBUILD=/Applications/...
46
votes
4
answers
25k
views
Deleting plist file does not reset app on macOS 10.9+
While developing a Cocoa application on 10.9, I have noticed that if I go to ~/Library/Preferences and delete the plist file for my app (to reset it), on the next build-and-run, the app behaves as if ...
46
votes
1
answer
62k
views
Is there a command-line interface to list all Bluetooth devices in range on mac? [closed]
I want to list all in-range Bluetooth devices, ideally with hostnames, but MAC addresses would be sufficient. I need a command that performs an active scan so I can poll to see if my device is nearby,...
45
votes
8
answers
12k
views
Launch Finder window with specific files selected
I'm trying to programmatically launch an OS X Finder window from an Xcode project. I need the window to open to a specific folder and have specific files within that folder automatically selected.
...
44
votes
3
answers
36k
views
How to get file size properly and convert it to MB, GB in Cocoa? [duplicate]
Possible Duplicate:
ObjC/Cocoa class for converting size to human-readable string?
I'm new in Cocoa. I'm trying to get size of folder files properly. And display it in MB if it less 1 GB , or in ...
44
votes
10
answers
69k
views
How to use NSString drawInRect to center text?
How can I draw a NSString centered within a NSRect?
I've started off with: (an extract from the drawRect method of my custom view)
NSString* theString = ...
[theString drawInRect:theRect ...
42
votes
9
answers
22k
views
Enable access for assistive devices programmatically on 10.9
I want to enable access for assistive devices programatically on 10.9. On 10.8 and lower I was using following Applescript to enable access for assistive devices:
tell application "System Events"
if ...
42
votes
3
answers
31k
views
What's the difference between formal and informal protocols in Objective-C?
What's the difference between formal and informal protocols in Objective-C?
41
votes
4
answers
13k
views
mouseEntered and mouseExited not called in NSImageView SubClass
I created a subclass of NSImageView to capture mouseEntered and mouseExited events.
But only mouseUp and mouseDown events are getting called. How to capture the mouseEntered and mouseExited events in ...