cocoa

Cocoa question: How to get file path for current open document for the front most application

南楼画角 提交于 2020-01-16 04:08:19
问题 I can get the front most application, how do I get the path for the front most document? 回答1: There isn't a way to do this for any app. Apps don't always have documents. If an app supports the standard AppleScript document model, you can do it with AppleScript. For example, tell application "TextEdit" set foo to the path of the first document end tell 来源: https://stackoverflow.com/questions/5976152/cocoa-question-how-to-get-file-path-for-current-open-document-for-the-front-mos

Calling xcodebuild from Swift command line tool fails

牧云@^-^@ 提交于 2020-01-16 01:11:06
问题 I'm writing simple swift command line tool application that automates some of my iOS Dev work. Everything is working except one thing - calling xcodebuild script. My method looks like this: func runTest(deviceName: String, os: String) { killAllSimulators() let sdk = "iphonesimulator" let destination = "platform=iOS Simulator,name=" + deviceName + ",OS=" + os let arguments = ["-workspace", workspace, "-scheme", scheme, "-sdk", sdk, "-destination", destination, "test"] executor.executeCommand(

Write to file does not work [duplicate]

余生颓废 提交于 2020-01-16 01:02:24
问题 This question already has answers here : File write with [NSBundle mainBundle] fails (5 answers) Closed 6 years ago . When i try to write to file with this code: NSString *path = [[NSBundle mainBundle] pathForResource:@"default" ofType:@"txt"]; NSError *error = nil; NSString*s = @"some text"; BOOL successful = [s writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:&error]; NSLog(@"%@",error); NSLog(@"%d",successful); Nothing happens. NSLog says: (null) 1 回答1: That's because

How to make round cornered NSTableView rows?

China☆狼群 提交于 2020-01-16 00:59:29
问题 I'd like to make something like this (on the new iTunes): As you can see when the row is selected it's "highlight" state is a round cornered row. How can I achieve something like this? 回答1: You need to subclass NSTableview and override -highlightSelectionInClipRect: method. It can be done like this: Change your tableView's highlighting mode from regular to Source list in Attributes Inspector : And now subclass NSTableView like this: -(void)highlightSelectionInClipRect:(NSRect)theClipRect {

NSNotificationCenter - Way to wait for a notification to be posted without blocking main thread?

≯℡__Kan透↙ 提交于 2020-01-15 20:16:15
问题 I'm using an AFNetworking client object which makes an asynchronous request for an XML document and parses it. Also using NSNotificationCenter to post a notification when the document has finished parsing. Is there a way to wait for a notification to be posted without blocking the main thread? E.g code: -(void)saveConfiguration:(id)sender { TLHTTPClient *RESTClient = [TLHTTPClient sharedClient]; // Performs the asynchronous fetching....this works. [RESTClient fetchActiveUser:

realm cocoa: predicate to select items not related

浪尽此生 提交于 2020-01-15 18:47:57
问题 in a model like this: class Order : RLMObject { dynamic var orderId = "" // ... other fields } class Product: RLMObject { dynamic var productId = "" dynamic var productName = "" } // This class relates products to orders, so an order may have multiple products and // a product may appear in multiple orders class OrderedProduct : RLMObject { dynamic var order: Order dynamic var product: Product dynamic var quantity: 1 } Question: How do I select all products that are not part of an order? here

Trouble with First Responder

[亡魂溺海] 提交于 2020-01-15 12:48:28
问题 I've had some trouble implementing some shortcuts in a document based application (i.e. Bold, Italic etc) available here: Connecting Menu Items in Document Based Applications The issue is that the method described disconnects the actual 'Bold' menu item from the Font Manager, and replaces it with my action I created (in this case, boldIt ). Because there can be only one sent action, it is replaced, not added. How can I overcome this? Very frustrating. If anyone can help me I would greatly

How to show an NSWindow as sheet at specific location

丶灬走出姿态 提交于 2020-01-15 11:40:19
问题 I have a window like this, having 3 subviews, each one of them has button. On click of those- I need to show sheet. By using this code, sheet comes in centre of the window. - (IBAction)closeSubWindow:(id)sender{ [NSApp endSheet:self.subWindow]; [self.subWindow orderOut:nil]; } - (IBAction)showSubWindow:(id)sender { [NSApp beginSheet:self.subWindow modalForWindow:self.window modalDelegate:self didEndSelector:nil contextInfo:nil]; } Is there any option or way to show the sheet at specific co

What replacement for UITableViewAutomaticDimension should I use to get the same effect in NSTableView?

不打扰是莪最后的温柔 提交于 2020-01-15 11:20:06
问题 In iOS projects I do something like that: tableView.rowHeight = UITableViewAutomaticDimension tableView.estimatedRowHeight = 30 and have nicely resizing cells. What should I do to reproduce the same behaviour in macOS project? Ok, func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat . Should I configure my SubView (cell view) (that actually is NSView) twice... In both methods - heightOfRow and viewFor tableColumn ? I heard about reusing of cells, but can it be done

NSTask and AuthorizationCreate

拟墨画扇 提交于 2020-01-15 11:17:54
问题 In my Cocoa application I need to run another application with root permissions, but it doens't work! NSTask doesn't have needed rights. AuthorizationCreate section is where i get needed permissions. Running NSTask is the section where I running another application. myStatus returns errAuthorizationSuccess. Here is the code //Authorization Create AuthorizationRef myAuthorizationRef; OSStatus myStatus; myStatus = AuthorizationCreate (NULL, kAuthorizationEmptyEnvironment,