cocoa

Encoding Line Feed Characters in the value of a NSXMLElement's attribute

十年热恋 提交于 2020-01-02 23:14:39
问题 The comment field of an XML database I'm reading and writing is stored as the attribute of an NSXMLElement. One entry contains a line feed (0x0a) character. These are encoded by a non NSXML encoder in the document I'm parsing as and get parsed correctly by NSXML. They result in the NSString containing the unicode value 0x0a 0x00 in memory (intel byte ordering). For example: <INFO BITRATE="192000" GENRE="Podcast" COMMENT="Test & More Test After the Line Feeds"</INFO> When writing this

Use Quick Look inside a Swift cocoa application to preview audio files

淺唱寂寞╮ 提交于 2020-01-02 22:27:13
问题 My application lists audio files (MP3) in a NSTableView, with the object for each row containing a path to the audio file. I would like to be able to preview an audio file with Quick Look (like in Finder) when hitting the space bar while one row is selected. By looking at related questions and answers, I noticed that the API seems to be private and so it's been very hard to find recent and reliable information or documentation about this, let alone in Swift. What's more, most examples I found

Using NSOutlineView as a file browser, starting from a given directory

徘徊边缘 提交于 2020-01-02 21:05:12
问题 I've been following this tutorial for using NSOutlineView as a hierarchical file browser: https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/OutlineView/Articles/UsingOutlineDataSource.html I used all the code in the tutorial and it worked. However, I then tried to call initWithPath: with a path other than / and it doesn't work: the fullPath of the top item (i.e. the folder specified in initWithPath ) is just the name of the folder, and the children method of the

Safe way of iterating over an array or dictionary and deleting entries?

倾然丶 夕夏残阳落幕 提交于 2020-01-02 20:29:30
问题 I've heard that it is a bad idea to do something like this. But I am sure there is some rule of thumb which can help to get that right. When I iterate over an NSMutableDictionary or NSMutableArray often I need to get rid of entries. Typical case: You iterate over it, and compare the entry against something. Sometimes the result is "don't need anymore" and you have to remove it. But doing so affects the index of all the rows, doesn't it? So how could I safely iterate over it without accidently

HTML editor Cocoa control

扶醉桌前 提交于 2020-01-02 19:48:22
问题 I am looking for a Cocoa HTML editor control. Do you know if something like this already exists? 回答1: Here's CKEditor4ObjC, an open-source Cocoa HTML editor using CKEditor and WebView that I just created. 回答2: The only thing that I've seen that relates to what you're looking for is this simple example of how to use the TinyMCE JavaScript-based HTML editor in a Cocoa WebView . Alternatively, I would take a look at this similar question and the corresponding link to helpful information that

Prevent OpenGL.framework from Loading in Cocoa App

笑着哭i 提交于 2020-01-02 19:46:32
问题 My application links against these Frameworks: Cocoa.Framework AppKit.Framework CoreData.Framework Foundation.Framework Note that OpenGL.Framework is NOT linked. However, after setting DYLD_PRINT_LIBRARIES=1, I note that: ... dyld: loaded: /System/Library/Frameworks/ OpenGL.framework /Versions/A/ OpenGL dyld: loaded: /System/Library/Frameworks/ OpenGL.framework /Versions/A/Libraries/... dyld: loaded: /System/Library/Frameworks/ OpenGL.framework /Versions/A/Libraries/... dyld: loaded: /System

Font issue with layer backed NSTextView

旧时模样 提交于 2020-01-02 19:32:41
问题 I have a small problem with the nstextview , when I send [textView setWantsLayer:YES] , the font in the textView become blurred, anybody know why is it? [[textView enclosingScrollView] setDrawsBackground:NO]; [textView setDrawsBackground:NO]; [textView setWantsLayer:YES]` 回答1: The problem here is likely with aliasing the text because the background color is transparent, thus causing it to alias against a transparent background, which is going to look pretty bad. Generally, I've found that I

In OS X (lion) how can I find whether a key combination is in use as a keyboard shortcut?

有些话、适合烂在心里 提交于 2020-01-02 19:14:30
问题 I want to put a bunch of keyboard shortcuts in my app (OS X lion) so I can do most things from the keyboard. There are of course a bunch of lists of hot key combos in use already, including the one in the HIG. Is there some utility that can be used to type a key combination and find out if it already means something (either globally, or mac standard -- I'm not too worried about reusing some special combo used by another app -- or should I be?)? 回答1: You can use Carbon to do this. Don't be

How to call a cocoa app from command-line outside?

这一生的挚爱 提交于 2020-01-02 19:12:34
问题 I want to use a command-line with a argument to call my cocoa app , but in my cocoa app ,how to receive the argument , this argument is a file path, thank you very much! 回答1: Neat thing: use NSUserDefaults . If you do: ./MyCocoaApp -argument /path/to/file.txt Then in your code you can do: NSDictionary * arguments = [[NSUserDefaults standardUserDefaults] volatileDomainForName:NSArgumentDomain]; NSString * path = [arguments objectForKey:@"argument"]; The key is the -argument switch, and the

How to call a cocoa app from command-line outside?

陌路散爱 提交于 2020-01-02 19:12:06
问题 I want to use a command-line with a argument to call my cocoa app , but in my cocoa app ,how to receive the argument , this argument is a file path, thank you very much! 回答1: Neat thing: use NSUserDefaults . If you do: ./MyCocoaApp -argument /path/to/file.txt Then in your code you can do: NSDictionary * arguments = [[NSUserDefaults standardUserDefaults] volatileDomainForName:NSArgumentDomain]; NSString * path = [arguments objectForKey:@"argument"]; The key is the -argument switch, and the