Questions tagged [core-foundation]
Core Foundation provides the fundamental data types and essential services that underlie both the Cocoa and Carbon environments on Mac OS X.
core-foundation
717
questions
336
votes
8
answers
191k
views
Generate a UUID on iOS from Swift
In my iOS Swift app I want to generate random UUID (GUID) strings for use as a table key, and this snippet appears to work:
let uuid = CFUUIDCreateString(nil, CFUUIDCreate(nil))
Is this safe?
Or ...
120
votes
5
answers
172k
views
iOS start Background Thread
I have a small sqlitedb in my iOS device. When a user presses a button, I fetch the data from sqlite & show it to user.
This fetching part I want to do it in a background thread (to not block the ...
74
votes
6
answers
45k
views
Testing file existence using NSURL
Snow Leopard introduced many new methods to use NSURL objects to refer to files, not pathnames or Core Services' FSRefs.
However, there's one task I can't find a URL-based method for: Testing whether ...
73
votes
3
answers
15k
views
Difference between Foundation Framework and Core Foundation Framework?
I try to get the hang of it, but for now both seem the same thing to me. However, Xcode allows to create an Console App with choice of using "Core Foundation" or just "Foundation". Maybe someone can ...
66
votes
8
answers
52k
views
Is there a constant for the maximum CGFloat value?
I need to create a CGSize to compute text height of an arbitrary text with arbitrary length. UIKit has this nice method -sizeWithFont:constrainedToSize: and my text is only constrained in width, but ...
34
votes
2
answers
12k
views
CoreFoundation vs Foundation
In iPhone development, speed is of the essence. Does anyone know if there is a speed difference between using a CoreFoundation type (like CFMutableDictionaryRef) versus a Foundation type (its ...
32
votes
7
answers
29k
views
Is there a method to generate a standard 128bit GUID (UUID) on the Mac?
Is there a built in function equivalent to .NET's
Guid.NewGuid();
in Cocoa?
My desire is to produce a string along the lines of 550e8400-e29b-41d4-a716-446655440000 which represents a unique ...
30
votes
7
answers
15k
views
How to convert CFArray to Swift Array?
According to Apple's "Using Swift with Cocoa and Objective-C", "In Swift, you can use each pair of toll-free bridged Foundation and Core Foundation types interchangeably". This makes working with ...
28
votes
5
answers
8k
views
JavaScriptCore console.log
I've put together a very simple program that uses JavaScriptCore to evaluate JS:
#import <CoreFoundation/CoreFoundation.h>
#import <JavaScriptCore/JavaScriptCore.h>
int main(int argc, ...
27
votes
5
answers
18k
views
Getting "global" mouse position in Mac OS X
How can I get in Mac OS X "global" mouse position - I mean how can I in cocoa/cf/whatever find out cursor position even if it's outside the window, and even if my window is inactive?
I know it's ...
25
votes
4
answers
27k
views
How do I create a UIImage from a CGImage in Swift?
I'm trying to create a UIImage from the ALAssetsGroup#posterImage method. In Objective-C, I could simply call [UIImage imageWithCGImage:group.posterImage] but in Swift, UIImage(CGImage: group....
24
votes
3
answers
10k
views
What is the purpose of the CoreFoundation framework? [closed]
I have been programming in Objective-C Cocoa for a little while using NSObjects etc. I see that there is another framework: CoreFoundation.As i look it over, it seems to be a C-Style framework.
So I ...
24
votes
2
answers
29k
views
What is NSSearchPathForDirectoriesInDomains?
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]
I used to know that sending a message to the object is kind of calling the method. However, I can't ...
23
votes
5
answers
10k
views
Toll-free bridging and pointer access in Swift
I am porting an App from Objective-C to Swift and I need to use the following method:
CFStreamCreatePairWithSocketToHost(alloc: CFAllocator!, host: CFString!, port: UInt32, \
readStream: ...
22
votes
4
answers
13k
views
Why would CFRelease(NULL) crash?
Is there a reason why CFRelease does not check for NULL? Isn't it unacceptable when [nil release]; free(NULL); delete NULL; all work perfectly fine?
22
votes
1
answer
5k
views
strong @property with __attribute__((NSObject)) for a CF type doesn't retain
UPDATE: This issue has been fixed as of Xcode 4.6!
This technique now works as intended again. However, make sure to read the notes at the top of Rob Napier's excellent answer before you use it in ...
20
votes
5
answers
9k
views
Releasing Core Foundation object references
Do I need to release a Core Foundation objects to clear up memory? And if so, how?
For example, in the code:
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef peopleArray = ...
20
votes
9
answers
17k
views
Converting plist to binary plist
Apple strongly recommends using the binary plist format when reading large XML-based data sets into iPhone apps. Among their reasoning is the fact that XML parsing is very taxing on the iPhone. ...
20
votes
4
answers
9k
views
Why doesn't this simple CoreMIDI program produce MIDI output?
Here is an extremely simple CoreMIDI OS X application that sends MIDI data. The problem is that it doesn't work. It compiles fine, and runs. It reports no errors, and does not crash. The Source ...
19
votes
2
answers
8k
views
NSCharacterSet - append another character set
I would like to create a character set that includes all of its own characters, as well as those from another character set. Append in other words.
I thought there'd be an obvious way, but after ...
18
votes
4
answers
13k
views
How to access CFDictionary in Swift 3?
I need to read and write some data from CFDictionary instances (to read and update EXIF data in photos). For the life of me, I cannot figure out how to do this in Swift 3. The signature for the call I ...
16
votes
3
answers
16k
views
How to enumerate CFProperyList / CFDictionary keys
I would like to iterate through a CFDictionary (CFPropertyList) and get all values on a specific level.
This would be my dictionary / property-list:
root
A
foo
0
bar
0
B
...
16
votes
8
answers
4k
views
Obtain Model Identifier string on macOS
Every Mac has a model identifier, for example "Macmini5,1". (These are shown in the System Information app.)
How can I programatically obtain this model identifier string?
16
votes
1
answer
3k
views
OSX FSEventStreamEventFlags not working correctly
I am watching a directory for file system events. Everything seems to work fine with one exception. When I create a file the first time, it spits out that it was created. Then I can remove it and it ...
15
votes
1
answer
9k
views
CFRunLoopRun() vs [NSRunLoop run]
I have an NSRunLoop object, to which I attach timers and streams. It works great. Stopping it is another story alltogether.
I run the loop using [runLoop run].
If I try to stop the loop using ...
14
votes
4
answers
9k
views
What's the right memory management pattern for buffer->CGImageRef->UIImage?
I have a function that takes some bitmap data and returns a UIImage * from it. It looks something like so:
UIImage * makeAnImage()
{
unsigned char * pixels = malloc(...);
// ...
...
14
votes
1
answer
533
views
Risks and rewards of using /dev/autofs_nowait on OS X
Throughout the CoreFoundation framework source, POSIX filesystem API calls (e.g. open(), stat(), et al…) are wrapped in an idiom wherein a descriptor on /dev/autofs_nowait is acquired – with open(…, 0)...
14
votes
1
answer
1k
views
Set non-owned window always on top - Like the app "Afloat"
I have set up a global hotkey with RegisterEventHotkey. When the user presses it, it gets the currently focused window with CGWindowListCopyWindowInfo, and then I need to set it always on top.
If the ...
14
votes
2
answers
936
views
my system refuses to shut down/restart with NSAppleScript class
I am using CFPlugin for contextual menu and icon overlay on 10.5(same as scplugin). For communication between my application and finder , i am using distributed object. After installing my plugin ...
13
votes
3
answers
11k
views
Determining what a CFTypeRef is?
I have a function which returns CFTypeRef. I have no idea what it really is. How do I determine that? For example it might be a CFStringRef.
12
votes
5
answers
10k
views
How do I implement a bit array in C / Objective C
iOS / Objective-C: I have a large array of boolean values.
This is an inefficient way to store these values – at least eight bits are used for each element when only one is needed.
How can I ...
12
votes
5
answers
3k
views
Convert method that returns an autoreleased CGColor to ARC
I'm in the process of converting my project to using ARC. I have a category on NSColor with a method that returns an autoreleased CGColor representation:
@implementation NSColor (MyCategory)
- (...
12
votes
1
answer
7k
views
reading value in CFDictionary with swift
I'm just starting with swift and cocoa. I'm trying to create a basic app that does image manipulation.
I've allready got all information of the image with this:
let imageRef:CGImageSourceRef = ...
12
votes
2
answers
3k
views
Retained Core Foundation Property
(Xcode 4.2, iOS 5, ARC)
I have some properties of Core Foundation (/Graphics) objects that should take ownership of their objects. Now in these Apple docs I found this:
In OS X v10.6 and later, ...
12
votes
5
answers
4k
views
How to resolve CGDirectDisplayID changing issues on newer multi-GPU Apple laptops in Core Foundation/IO Kit?
In Mac OS X, every display gets a unique CGDirectDisplayID number assigned to it. You can use CGGetActiveDisplayList() or [NSScreen screens] to access them, among others. Per Apple's docs:
A ...
12
votes
1
answer
2k
views
iOS Crash Core Location CFBasicHashCreateCopy?
I've got this issue being reported via Crashlytics, although I've been unable to replicate it locally, so I've got nothing to go on other than the stack trace below.. Not sure if the references to ...
11
votes
1
answer
4k
views
Convert NSData to sockaddr struct in swift [duplicate]
I'm trying to do a simple DNS lookup in swift. So far, here is the code that I have:
let hostRef = CFHostCreateWithName(kCFAllocatorDefault, "google.com").takeRetainedValue()
var resolved = ...
11
votes
2
answers
4k
views
Core Foundation equivalent for NSLog
What is the closest Core Foundation function to the functionality of NSLog?
10
votes
5
answers
8k
views
In Objective-C, how to print out N spaces? (using stringWithCharacters)
The following is tried to print out N number of spaces (or 12 in the example):
NSLog(@"hello%@world", [NSString stringWithCharacters:" " length:12]);
const unichar arrayChars[] = {' '};
NSLog(@"...
10
votes
3
answers
14k
views
What is an NSCFDictionary?
I'm getting an NSCFDictionary returned to me and I can't figure out how to use it. I know it's of type NSCFDictionary because I printed the class and it came out as __NCSFDictionary. I can't figure ...
10
votes
3
answers
5k
views
How can I clear the contents of an NSMutableAttributedString?
I have an ivar which is alloc-inited in the init of an object:
attString = [[NSMutableAttributedString alloc] init];
On a loop, I want to clear the contents of attString and re-use it. How do I do ...
10
votes
2
answers
8k
views
How can I find the path to a file in an application bundle (NSBundle) using C?
Is there a C API for finding the path to a file in an application bundle?
I know that this can be done in Objective-C with the following syntax.
NSString *path = [[NSBundle mainBundle] ...
10
votes
2
answers
6k
views
Using IOHIDManager to Get Modifier Key Events
I'm trying to use IOHIDManager to get modifier key events because Cocoa flagsChanged events are lacking (difficult to differentiate between press/release, left/right if both are down, etc.) Here's the ...
10
votes
1
answer
2k
views
Is it safe to schedule and invalidate NSTimers on a GCD serial queue?
What's the right way to do this? The NSTimer documentation says this:
Special Considerations
You must send this message from the thread on
which the timer was installed. If you send this ...
9
votes
6
answers
9k
views
AVAssetWriterInputPixelBufferAdaptor returns null pixel buffer pool
I'm sure something's wrong with my buffer attributes, but it's not clear to me what -- it's not well documented what's supposed to go there, so I'm guessing based on CVPixelBufferPoolCreate -- and ...
9
votes
1
answer
5k
views
Swift: CGPathRelease and ARC
Just updated to Xcode Beta 4, and noticed the following compiler error with my code below:
var path = CGPathCreateMutable()
...
CGPathRelease(path)
'CGPathRelease' is unavailable: Core Foundation ...
9
votes
1
answer
5k
views
Get NSWindow* from CGWindowListCopyWindowInfo
I have accomplished listing all the windows (in z order from front to back I think/hope) using CGWindowListCopyWindowInfo but I am having an issue getting the NSWindow* from it so I can use with ...
9
votes
2
answers
2k
views
Folding/Normalizing Ligatures (e.g. Æ to ae) Using (Core)Foundation
I am writing a helper that performs a number of transformations on an input string, in order to create a search-friendly representation of that string.
Think of the following scenario:
Full text ...
9
votes
2
answers
4k
views
Returning an autorelease'd CFTypeRef with ARC
I am new to Automatic Reference Counting with LLVM and Objective-C, and have a question about returning CGImageRefs from my Objective-C function. In the days of manual reference counting, it was ...
8
votes
7
answers
6k
views
Xcode 7 Beta 6, dyld ___NSArray0__ crash
For the first time I was able to compile my app in Xcode 7 (failed in beta 4 and 5). So, thats good progress I guess.
However, when i load my app on my iPhone 6, iOS 8.4.1, it crashed in the debugger ...