FAQ Database Discussion Community


First OpenGL program from the Red book inside a Mac OS Cocoa NSOpenGLView

c++,objective-c,osx,cocoa,opengl
What I want to do is to simply run the first OpenGL program from the Red Book (triangles.cpp) inside a NSOpenGLView, but my app only clears the screen to black and does not draws the required triangles (even though the shaders were compiled successfully). (One side note: If I use...

Bindings working from IB, not from my addObserver…

cocoa,cocoa-bindings
My Document-based app was created without storyboards in Xcode 6.3 so it began life without a window controller (I still don't have a window controller -- just trying to give some background and context). I have a class structure implemented for working with a gradient and storing it's formative values...

Restrict input on NSTextField

osx,swift,cocoa,nstextfield
I want to restrict character input on NSTextField, i.e. so that disallowed characters aren't even appearing. Most of what I found about this topic were solutions that only validate after text input finished or using NSFormatter which still allows the character to appear. So far I came up with this...

NSScrollView: fade in a top-border like Messages.app

objective-c,cocoa,core-animation,calayer,nsscrollview
What I Want to Do: In Messages.app on OS 10.10, when you scroll the left-most pane (the list of conversations) upwards, a nice horizontal line fades in over about 0.5 seconds. When you scroll back down, the line fades back out. What I Have: I am trying to achieve this...

Most efficient way to create an NSMutableArray from NSArray

objective-c,cocoa,cocoa-touch,nsmutablearray,nsarray
Which of these, if either, is more efficient? NSMutableArray *array = [NSMutableArray arrayWithArray:@[@1, @2]]; or NSMutableArray *array = [@[@1, @2] mutableCopy]; Or are these the same internally?...

Set CALayer Gradient Background

objective-c,xcode,osx,cocoa,cocoa-touch
I am trying to add a gradient to a CALayer I have created. I can set the background colour of the CALayer with the following: self.colorLayer = [CALayer layer]; [self.colorLayer setBackgroundColor:color.CGColor]; [self.colorView setWantsLayer:YES]; [self.colorView setLayer:self.colorLayer]; I've looked around with no success (surprisingly I thought this would have been answered many...

How to set canBecomeKeyWindow?

xcode,osx,swift,cocoa
This may be very trivial question but I am not able to figure it out. I have removed titlebar of a window by- self.window?.styleMask = NSBorderlessWindowMask self.window?.movableByWindowBackground = true Now Any textfield is not working and are disabled because without title bar canBecomeKeyWindow is set to false. Please refer This...

How to safely test whether a method can be called through NSInvocation

swift,cocoa,objective-c-runtime,scripting-bridge
I've generated a list of methods and properties of a class using the ObjC runtime, so that those can be called later from a bridge using NSInvocation. The problem is that for those methods that the runtime can't generate a signature I'm getting an error. For instance calling the property...

Initializing a xib view as a subview of another NSView

objective-c,osx,cocoa,xib,nib
I'm trying to learn OSX development, and I've created a view in a .xib file, and I'm trying to initialize and then add this view as a subview. I've googled how to do this, and all of the solutions are for iOS and use a call such as MyViewClass* myViewObject...

blocks and the stack

cocoa,objective-c-blocks
According to bbum: 2) Blocks are created on the stack. Careful. Consider: typedef int(^Blocky)(void); Blocky b[3]; for (int i=0; i<3; i++) b[i] = ^{ return i;}; for (int i=0; i<3; i++) printf("b %d\n", b[i]()); You might reasonably expect the above to output: 0 1 2 But, instead, you get: 2...

How to guarantee that an NSColor has enough saturation?

swift,cocoa,nscolor
I need to guarantee that a color has enough saturation. I made this extension to NSColor but my tests give me weird values: tempColor always seems to have lots of saturation. So basically my function always returns self? Where's my mistake? I've also tried without converting to NSCalibratedRGBColorSpace but that...

Binding an NSTableView to an array of strings in Swift

osx,swift,cocoa,nstableview,cocoa-bindings
I'm showing the contents of an array of strings with an NSTableView via binding through an Array Controller. I have "NSString" in Class Name in the attributes inspector for the Array Controller and in the Model Key Path of the Array Controller's binding inspector I have the path to my...

updateTrackingAreas: override only works for the first 2 times?

objective-c,xcode,osx,swift,cocoa
On El Capitan in Xcode 7 beta using Swift 2.0, I subclassed a NSView to use as a prototype view of NSCollectionView's item view, and override the updateTrackingAreas: method to do the mouse tracking. The NSCollectionView was inside a NSPopover. It seems that only the first 2 times the updateTrackingAreas:...

Core Data inputting numbers > 1.0 error

ios,cocoa,cocoa-touch,core-data,nsnumber
I'm working on coding a journal application which uses core data to store amongst other things, theme data (what the app looks like) - this was working until recently when I changed quite a lot of code. I'm now coming across an issue when trying to import a float into...

How to get storage capacity of mac programatically?

objective-c,xcode,osx,cocoa,storage
I am having a mac app. As shown in the screenshot, I want to get this programmatically in my cocoa application for Mac OS X. I want to get the total capacity, available space and free space. Can anyone help me on this? Thanks......

Getting NSTableView row index of focussed row?

osx,swift,cocoa,nstableview
How can I obtain the index of the row in a NSTableView that is currently being focussed? When left-clicked the row is selected but I need the index when the row is right-clicked on, i.e. the row might not be selected when the user opens a context menu upon it...

What is the best way to make sure I am not using any unavailable API's on OSX?

objective-c,xcode,osx,cocoa
I am writing an OSX app in Xcode 6 but want my application to have support for OSX 10.7 and up. Unfortunately Xcode 6 only includes SDK for 10.10 and 10.9. What is the best way to make sure I am not using any unavailable API's that would crash on...

Default Cocoa Application ViewController.m issue?

objective-c,osx,cocoa
Newbie question follows... I am learning Objective C based OS X Cocoa app development. Most of the books and videos I have are for iOS, so I am converting some simple iOS code examples to OS X. When I create a new OS X "Cocoa Application" project, with the "use...

NSViewController delegate?

swift,cocoa
I'm new to using delegates in Swift, and I can't seem to figure out how to communicate with my View Controller from a different class. Specifically, I call the custom class's functions from my App Delegate, and then from within that custom class, I call a function within my View...

“stringByAddingPercentEncodingWithAllowedCharacters” replaces more characters than it should

swift,cocoa,escaping
Playing around with Swift I came across something I do not understand. The following code replaces not only the /% characters as intended, it also replaces the ä character: immport Foundation extension String{ func encode() -> String{ let customAllowedSet = NSCharacterSet(charactersInString:"/%").invertedSet return self.stringByAddingPercentEncodingWithAllowedCharacters(customAllowedSet)! } } let testStr = "Ein String...

Apply Core Image Filter to Video on OS X using Swift

swift,cocoa,avfoundation,core-image,core-video
I am planning to build an NSOpenGLView for an OS X app using SWIFT which can be used to apply Core Image Filter and effects to a video, so far I have worked on the code for the video Controller to add video playback, but I am not sure how...

Setting editable on a NSTextField doesn't have any effect

osx,cocoa,cocoa-bindings,nstextfield
I have an NSTextField in a view that is bound to a value in the view's view controller. When a button is pressed I wish to make the text field no longer editable so I use the following code: - (IBAction)makeTextFieldNotEditable:(id)sender { self.textField.editable = NO; } Everything is bound correctly...

Mac - How to programatically hide NSApplicationActivationPolicyAccessory or LSUIElement application?

osx,cocoa
I have a small Swift-based Cocoa app that I'm writing. It's a single window app, something like Spotlight/QuickSilver/Alfred. It's set as NSApplicationActivationPolicyAccessory (docs) (though I've tried the same thing using LSUIElement, which is equivalent). It's activated via a global hot key. Everything works well, except that when it's active I...

Capture the space key in a window containing several NSTextFields

objective-c,osx,cocoa,keyboard-events,nstextfield
I have a large window with a number of NSTextField fields on it, and I would like to intercept the space bar even while any of the text fields have focus, so that pressing space at any time will cause a separate action. Subclassing NSTextField and overriding -keyUp: allows me...

Cocoa: initWithFrame from a custom view proxy is not being called

osx,cocoa,initwithframe
According to apple's document Creating a Custom View this method should be called if you're using a custom view proxy in the Interface Builder. If you have not created an Interface Builder palette for your custom view, there are two techniques you can use to create instances of your subclass...

creating a wrong NSDate

ios,objective-c,iphone,cocoa,nsdate
This is the code NSDateComponents *comps = [[NSDateComponents alloc] init]; [comps setDay:13]; [comps setMonth:6]; [comps setYear:2015]; NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDate *date = [gregorian dateFromComponents:comps]; NSLog(@"date = %@", date); the result is 2015-06-12 23:00:00 +0000 12? the day is 13!!! Why is that happening? Bug? ...

How do you work with views in MainMenu.xib?

objective-c,xcode,osx,cocoa
I'm coming over from iOS development and I can't figure out this basic thing: if I open MainMenu.xib in Interface Builder and I drag a button onto the main window's view, what class should I connect that button's action to -- the App Delegate? If I want to add a...

NSCollectionView does show nothing

cocoa,cocoa-bindings,nscollectionview,kvc,nscollectionviewitem
I've tried to follow this guide: Quick Start for Collection Views using an NSImageView in the Collection View Item. Nothing shows up, neither if i set the image with a Image Well neither if i set the array via code. So i tried to do it programmatically, using func representedObject(representedObject:...

Cocoa bindings not reading a nil value from user defaults

objective-c,osx,cocoa,cocoa-bindings
I have two UI components whose values are synchronized through user defaults. The first one is essentially an input field, the other a menu item. When the value of the input field changes, the key equivalent of the menu item changes through Cocoa bindings: Input Field -> NSUserDefaultsController -> User...

Layout still needs update after calling NSTableRowView layout

osx,swift,cocoa,autolayout,nstableview
I have two NSTableView's in my app and the user can drag and drop items from table A to table B. When dragging an item to table B Xcode gives me the following layout warning message: Layout still needs update after calling -[NSTableRowView layout]. NSTableRowView or one of its superclasses...

How to get custom table cell views into NSTableView?

osx,swift,cocoa,nstableview,nstableviewcell
I have a NSTableView that uses mostly standard NSTextTableCellViews but I want some other cells that contain another UI component in my table in one or two rows. The question is: Where do I define those custom cells so that Cocoa finds them? I just dropped a custom NSTableCellView into...

How to set the default writing direction for NSTextView?

osx,swift,cocoa,interface-builder,nstextview
I'm trying to set up a text view that a user can type Hebrew text into from right-to-left. Currently it defaults to a left-to-right text direction, which the user can manually change by right-clicking and selecting "Writing Direction > Right to Left", but what I need is for the text...

Selecting global or object function

swift,cocoa,swift2
I am working with on a Cocoa project in Swift and confronted the following problem: Several classes in the Cocoa Framework (such as NSWindow or NSView) implements a function called print: that opens a window in order to print something (don't really know what), so when I work within a...

NSBezierCurve not drawing lines

swift,cocoa
I tried drawing on NSImageView, and if I want to draw an oval, it works. If I try drawing a line, it fails. Why? My object declaration: class MyImgView: NSImageView { var color = NSColor.greenColor() var point1 = NSPoint() var point2 = NSPoint() init(frame: NSRect) { super.init(frame: frame) self.setNeedsDisplay() self.point1...

App crash after hammering button

multithreading,osx,swift,cocoa,core-data
In my app the user has to press a button to generate data which is created and processed in a dedicated thread and afterwards stored via Core Data. The button is immediately being disabled after it's pressed and is only again enabled after the data was saved via Core Data....

How to animate NSAttributedString?

ios,objective-c,osx,swift,cocoa
I need to animate the color and scale of an attributed string. CATextLayer does not work for me, because it can only change the foreground color for plain strings.. I found another solution, but I did not get it to work either Link I need to get it to work...

Access Default Window Color Cocoa

cocoa,window,nscolor
I have a SKView with a picture of a keyboard in a window as shown below. I would like the background color of the SKScene it's presenting to be the same color as the window behind it, so that it would appear as if the keyboard was just in the...

Change views inside NSSplitViewController

swift,cocoa,nssplitview
I'm trying to migrate my Objective-C and now improving Swift knowledge to an application for Mac OS X. Steep learning curve! I'm trying to load a NSSplitViewController with different views in the "detail view" depending on buttons pressed on the "master view" if you will. Following tutorials and searching for...

Swift NSViewController responds to mouseDown event, but not keyDown event

cocoa
I am trying to create an application for OS X using Swift and Cocoa. I want the application to respond to key events without the focus being on/in a text field. I created a new Cocoa project with storyboards in Xcode, and have modified the ViewController.swift class to the following:...

NSPredicate crash with path which contains square brackets

objective-c,cocoa,nspredicate
I have to search paths which contains square brackets in it from core data. But when I trying to create search query like below, xcode crashes. path == /my/local/[path] I've tried to escape square brackets, from one brackets to 16 brackets, but nothing works. That path is from another application,...

NSRTFPboardType & paste into gmail browser window?

objective-c,cocoa,rtf,nspasteboard
I have a NSTextView which contains some text with attributes (syntax highlighting). I'm trying to have a copy option which keeps the syntax highlighting so that I can paste it into a gmail text window. Currently the highlighting does not appear when I copy paste it, however if I were...

(OSX/Cocoa) How to set controller for main window

objective-c,xcode,osx,cocoa,nswindowcontroller
I've created a new cocoa application using .xib files (not storyboarded, the app has to be backwards compatible with mavericks/mountain lion) and I would like to have a custom windowcontroller for the main window. Is this possible? I can't seem to find a way to connect the window to my...

NSTreeController: how do I find the parent of a node?

objective-c,osx,cocoa,nstreecontroller
I'm looking for a similar method to: NSOutlineView parentForItem: for NSTreeController. I need to know the parent of a node in the tree....

QLPreviewView can not show the quicklook preview in sandbox

osx,cocoa,sandbox,appstore-sandbox,quicklook
I use QLPreviewView to show the quicklook preview in the app. Without sandbox, this works well, but once change the app to sandbox, the preview can not show up. I found the error in Console: QuickLookUIHelpe(20786) deny file-read-data XXX. I have used the security-scoped bookmarks & com.apple.security.files.user-selected.read-write to grant access...

Setting the NSImage of a NSImageView from a NSURL

objective-c,osx,cocoa,nsimage,nsimageview
Okay, so I'm a newbie trying to write a practice app where you click a button, an NSOpenPanel appears, you select an image file, and the image gets displayed in an NSImageView. I've got the open panel working okay, and it returns an NSArray of NSURLs. I avoided using filename...

Why Does Apple use “flags” Structs In Their Classes?

objective-c,c,osx,cocoa,struct
My question is about style/structure in Apple's Objective-C headers. Take NSSplitViewItem, for example: NSSplitViewItem (Apple): @interface NSSplitViewItem : NSObject { @private id _splitViewItemPrivateData; struct { unsigned int _collapsed:1; unsigned int _canCollapseFromDrag:1; unsigned int _canCollapseFromDoubleClickOnDivider:1; unsigned int _reserved:29; } _flags; } Why the Struct? Why does Apple seem to favor using...

Xcode build error 'InputFile' should have exactly five arguments

osx,cocoa,xcode6
I am using Xcode 6.2 (6C131e) to build my cocoa project. It was working very smoothly but today i got following error: 2015-06-01 11:53:59.911 xcodebuild[2060:184936] error: InputFile /Users/parag/workspace/myapp for Mac/Mac/HelperTool-Prefix.pch 0 1429610467 187 33188... malformed line 9; 'InputFile' should have exactly five arguments Can anyone please help me out?...

Too many arguments to function call, expected 0 method_invoke

objective-c,cocoa,objective-c-runtime
I'm trying to run the method id method_invoke ( id receiver, Method m, ... ); from the Objective-C runtime library but the compiler is saying I'm passing too many arguments, with it expecting 0. Why might this be? (swizzledMethodOriginalImplementation is of type Method) -(NSMenu*) blah2: (NSEvent*)anEvent :(NSRect) cellFrame :(NSView*) aView...

Stop async operations on window close

swift,cocoa,appdelegate
In my app delegate I have put the callback to stop the program when the window is shut. func applicationShouldTerminateAfterLastWindowClosed(sender: NSApplication) -> Bool { return true } This doesn't work however because (I assume) there is an async bluetooth task running. What is the best way to stop everything running...

How do I add my own option to Finder's right click menu?

objective-c,osx,cocoa,contextmenu,finder
I have an app that basically takes a file path(s) and copies the data name and extension from it to be used in my app. I was wondering how to add on to the Finder right click menu (like Dropbox does) and do run some Objective-C code when clicked. (I...

Launch app at login in OS X 10.10 Yosemite

osx,cocoa,osx-yosemite,yosemite
I need to add my application to the login items in the system preferences when then user presses a button. I've seen other answers around Stack Overflow, but many of them rely on <10.8 or <10.10 and deprecated APIs like LSSharedFileServices. Some of the answers refer to LSSharedFileServices, to which...

Use NSWindow or NSViewController?

osx,cocoa
If I just have a window with elements that are not removed/added, should I process all the events and other things in NSWindow, or should I create NSViewController?

Cursor doesn't update in NSTextField as it autoresizes when resizing the enclosing NSWindow

objective-c,cocoa,nstextfield,autoresize,nscursor
I have an NSTextField that autoresizes. Its text is centered. When I start typing in the field and then resize the enclosing NSWindow, the cursor stays where it's at rather than repositioning to the appropriate place : I've also made an XCode project demonstrating this problem : https://www.dropbox.com/sh/cohhmslyl9ti43b/AAC6ULteopsQCMDsEArJU15Ta?dl=0 Does anyone...

How to handle Check Box clicks in a cell based NSOutlineView

swift,cocoa,nsoutlineview
I'd like to handle clicks on check boxes in NSOutlineView. Check boxes are Check Box Cell of type NSButtonCell. I'm able to set the initial state in: optional func outlineView(_ outlineView: NSOutlineView, willDisplayCell cell: AnyObject, forTableColumn tableColumn: NSTableColumn?, item item: AnyObject) Now, how can i execute a function when the...

Cocoa Touch Framework: Constants

objective-c,swift,cocoa,cocoa-touch
i want to write a Cocoa Touch Framework in Swift and want to use it in different projects. As far as everything works fine. Now I would like to extend my framework with constants which I can use outside of the framework. My problem is that i can't use the...

Reference main NSWindow in AppDelegate using Storyboard?

xcode,swift,cocoa,interface-builder
I am attempting to set an outlet for the main window of my app in my App Delegate, then connect it within Interface Builder. I create the outlet within my App Delegate easily: @IBOutlet weak var mainWindow: NSWindow! However there's no way, within interface builder, for me to connect a...

Open New Window in Swift

osx,swift,cocoa,storyboard,nswindow
I am trying to open a new window in my Swift application but I cannot get it to open. class AppDelegate: NSObject, NSApplicationDelegate { func applicationDidFinishLaunching(aNotification: NSNotification) { openMyWindow() } func openMyWindow() { if let storyboard = NSStoryboard(name: "Main",bundle: nil) { if let vc = storyboard.instantiateControllerWithIdentifier("MyList") as? MyListViewController { var...

How to create few apps in one bundle?

objective-c,osx,cocoa
I have an application that runs as an agent and has icon in the top bar. It should be able to run another app with window and icon in the dock. Both should to share same core data. Is there way to do it? How to open one app from...

Why @selector can call a method which is declared in an implementation file?

objective-c,cocoa,nsnotificationcenter
I have declared (between @interface and @end) and implemented a method in the .m file of Class A. For instance: - (void)zoneChange:(NSNotification *)note { NSLog(@"The system time zone has changed!"); } And in Class B, I want to send zoneChange message to a observer when the system zone is changed....

Delphi - OSX - How to extend NSWindowDelegate

osx,cocoa,delphi
The current NSWindowDelegate implementation in Delphi is very limited. It doesn't include events such as windowWillResize:toSize: How can I extend it? I can see the code in source\rtl\osx'Macapi.Appkit.pas so I tried to make a copy of that file to my application folder and include it in the project. However, after...

Safari toolbar UI Design, How to integrate a add button like Safari does it?

cocoa,nstoolbar
Is there is a NSToolbar trick to integrate a add ("+") button in the right lower toolbar corner like Safari does it? ...

NSTableView textfield cell should not go into edit on click

osx,swift,cocoa,nstableview,nstextfield
I have two NSTableViews in my app and both are set up the same, same parameters, etc., they have several columns with NSTextField cells and the first column is editable. The first table behaves like I want it: if the user clicks, the row is selected. If the user clicks...

Does it necessary to go back to main thread to update UI?

ios,objective-c,cocoa
I was using AFNetworking to deal with the http request.And here is my code: AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; [manager POST:URL_LOGIN parameters:parames success:^(AFHTTPRequestOperation *operation, id responseObject) { [self.tableview reloadData]; } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Request failed"); }]; or: AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; [manager POST:URL_LOGIN parameters:parames...

How to set screensaver thumbnail in Settings panel on Mac?

osx,cocoa,screensaver
I'm making a custom *.saver application, and I would like to add my own thumbnail to show up above the name of screensaver (the ladybug pictures in the left column). How do I do that? ...

Using custom NSValueTransformer subclass with bindings and reverseTransformedValue method

objective-c,cocoa
I'm writing a Cocoa App using Bindings. I have a NSSlider as well as a NSTextField. Whereas the Slider's value is bound to the value returned by the transformedValue method, the TextBox should be bound to the reverseTransformedValue method. How may I achieve this? For the Slider I entered the...

NSIndexSet.enumerateIndexesUsingBlock using Swift Closure

osx,swift,cocoa,iteration,nsindexset
I'm writing a method to copy data from a table view to the paste board but if any rows are selected it should specifically only copy the data from the selected rows so I need to iterate over the index set ... func createExportText(fromArrayController:NSArrayController) -> String { var indexSet =...

Is it possible to obtain an unique iCloud user ID on cocoa?

ios,iphone,cocoa,ipad,icloud
My iOS app is currently on beta in TestFlight, and as a way to retribute to the nice people who helped me test it I would like to offer them some goodies such as, for instance, the full final version of the app for free. For this, I was thinking...

NSTableView - how to get automatic and manual sorting working together?

osx,swift,cocoa,sorting,nstableview
I have a NSTableView in MyViewController and have an array controller bound to it. I want to be able to sort it by clicking the table column headers and it should also auto-sort. So for auto-sort I set the Sort Descriptors binding of my array controller in IB as following:...

SMLoginItemSetEnabled - Start at Login with App Sandboxed - Xcode 6.3 (Illustration)

objective-c,xcode,osx,cocoa
How to make app with Start at Login function when app sandboxed?

How do I customize NSOutlineView to have border color?

objective-c,osx,cocoa,interface-builder,nsoutlineview
I have looked over the google but have not found many examples on this. Most only relate to the NSTableView. How do I subclass my NSOutlineView to look exactly like XCode's plist editor? I've do not know how to get the border colors shown below. I currently have it working...

Disabling the NSTableView row focus ring

osx,swift,cocoa,nstableview
How do you disable the focus ring around an NSTableView row when the user right-clicks on it? I can't get it to disappear. Setting focus ring of an individual NSTableViewCell in the table to None has no effect. ...

How to not crash your app on quit when using concurrency

objective-c,osx,swift,cocoa,nsoperation
I'm using NSOperationQueue and a subclass of NSOperation for a part in my app that is generating a lot of data and therefore is very calculation-heavy. When the app is closed by the user processingQueue.cancelAllOperations() is called. Also in my NSOperation subclass I overwrote cancel() to let it forward a...

Keep both NSSplitViewController's child controllers in first responder chain

osx,cocoa
I've a document based app with an NSSplitViewController as the main window's content view controller. The left pane contains a custom view with controller, which implements some menu commands. The right pane contains a standard NSTableView with controller. When the app starts the menu commands work as expected, but as...

cocoa tooltip delay per object?

objective-c,osx,cocoa,nstableview
According to this article, you can change the tooltip display for your applications by modifying the NSInitialToolTipDelay user default. So far, this seems to be the only way I have found to modify how long it takes to display a tooltip, however it seems to be application wide. Does anyone...

Command-Line Testing Using Cocoa Touch

xcode,cocoa,kif
I have developed several test for an application, and I would like to run this application using the command-line. I have read this tutorial; however, I haven't been able to run them. When executing the following command: xcodebuild test -project MyApplication.xcodeproj -scheme MyApplication -destination 'platform=iOS Simulator,name=iPhone 6' I am getting...

Overuse of NSView -> Alternatives?

objective-c,osx,performance,cocoa,nsview
I having some Performance troubles with my app: It takes more than 2 seconds to load -> So straight away I went to Apple documentation https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CocoaPerformance/Articles/CustomViews.html#//apple_ref/doc/uid/TP40001443-CJBJIFGC In the section named "Avoid the Overuse of Views" at the bottom I got very confused: I indeed adding a lot of NSViews (Guess...

What is a “non-weak zeroing reference”

objective-c,cocoa,memory-management,nsnotificationcenter,osx-elcapitan
In the OS X v10.11 beta release notes, I find the following: NSNotificationCenter and NSDistributedNotificationCenter no longer send notifications to registered observers that may be deallocated. If the observer is able to be stored as a zeroing-weak reference the underlying storage stores the observer as a zeroing weak reference. Alternatively,...

How to get NSTableView to use a custom cell view mixed with preset cell views?

osx,swift,cocoa,nstableview,nstableviewcell
I have a NSTableView configured in Interface Builder which uses several default cell views. However the first column's cell view needs to be created from a custom class. How do I implement NSTableViewDataSource method tableView.viewForTableColumn() so that it creates the default cell views for the remaining columns? Here's my method...

self.revealViewController becomes nil and SWRevealViewController Menu not showing after segue back to SWRevelViewController from a certain VC

ios,objective-c,cocoa
I'm using the SWRevelViewController framework and met this problem while coding. Basically here's the list of my VCs and their classes: http://mnch.in/ubyB/3g4uqSwl (picture of my story board) The problem is when user logged in in UIVC_2, it goes back to SWRevelVC using the segue marked in blue. However, when the...

Close and launch with different command line parameters/arguments

osx,cocoa
I am running a .app and I need to "restart" it so to speak. Basically I need to tell it to close, then after closing, it should launch the path i tell (which is to itself) with some command line arguments. Is this possible with cocoa? Im getting stuck at...

Why does the window background remain black in fullscreen?

osx,swift,cocoa,xcode6,storyboard
I have created a window without title by- override func windowDidLoad() { super.windowDidLoad() self.window?.styleMask = NSBorderlessWindowMask self.window?.movableByWindowBackground = true } I have set canBecomeKeyWindow by- override var canBecomeKeyWindow:Bool { get{ return true } } I have changed the background color of container view by- override func drawRect(dirtyRect: NSRect) { super.drawRect(dirtyRect)...

Unified title and toolbar in swift with storyboards without title visibilty

osx,swift,cocoa,xcode6
I want unified title toolbar like in calendar app without title. I have tried following- in viewDidLoad I added- self.view.window?.titleVisibility = .Hidden I have selected unified title and toolbar in attribute inspector. I also tried adding titleVisibility to 1 in user defined runtime attributes in identity inspector. I am not...

Please help protocol code that does not make sense

ios,objective-c,cocoa
i'm stumped with part of this statement: @property(nonatomic, readonly) NSArray <id<NSFetchedResultsSectionInfo>>*sections this property belongs to NSFetchedResultsController Class. although NSFetchedResultsSectionInfo is a protocol, id<NSFetchedResultsSectionInfo> is an object type that must conform to the NSFetchedResultsSectionInfo protocol. id<NSFetchedResultsSectionInfo> is not a protocol so enclosing them in angle brackets <id<NSFetchedResultsSectionInfo>> makes no sense. the...

NSRegularExpression with template in Swift

regex,swift,cocoa
I'm obtaining a response to an HTTP POST request with the code let task = NSURLSession.sharedSession().dataTaskWithRequest(request) {data, response, error in if error != nil { println("error=\(error)") return } // Get the response to the HTTP POST var responseString = NSString(data: data, encoding: NSUTF8StringEncoding)!} task.resume() I tried to define two regular...

Change NSTextField border and BG color while editing

osx,swift,cocoa,nstextfield
I have a NSTextField that uses no border and window background color while it is displayed but I want it to change to have the default border and white BG color when being edited. I know I can change these properties with: nameTextField.bezeled = true nameTextField.backgroundColor = NSColor.textBackgroundColor() What I...

Cocoa ViewController.m vs. Cocoa Touch ViewController.m

objective-c,osx,cocoa
Total newbie question follows... I am learning Objective C based Cocoa (OS X) app development. Most of the books and videos I have are iOS based, so I'm seeing how the two platforms differ. I have converted a simple iOS app to OS X. I got the converted OS X...

Remove port from NSURL

objective-c,cocoa,nsurl
How can one normalise an NSURL, removing the port in particular? http://en.wikipedia.org/wiki/URL_normalization

How can I check if an appearance property has been set?

ios,objective-c,cocoa,uikit
Is there a way to check if a property has been set on an UIAppearance proxy or not? Let's say I want to do something like: self.lineWidth = appearance.lineWidth ? : kDefaultLineWidth; This will not work correctly if the lineWidth was set to zero on the proxy since it would...

Sorting the results of an NSFetchRequest of objects that implement compare:

objective-c,cocoa,core-data,nsfetchrequest,nssortdescriptor
I have a NSManagedObject subclass that implements the compare: message. I want to retrieve these objects and sort them using this compare method, but apparently I have to provide a key for the NSSortDescriptor. I don't want to provide any key, as the object itself already knows how to compare...

Imports and includes in header files - when is it okay?

objective-c,cocoa,cocoa-touch
I've read that the rule is to not #import or #include anything in .h files. Is that really true, though? Just today I've run into two separate occasions where I had to do it, one where I import a header file that contains a typedef enum because my method stubs...

Sending replyToApplicationShouldTerminate to NSApplication in Swift

swift,cocoa,nsapplication
Here is my AppDelegate.swift. I implement the applicationShouldTerminate protocol from NSApplication. Which answer I give depends on the status of is.Started in the mainWindowController. (This is the SpeakLine example from Cocoa Programming for OS X: The Big Nerd Ranch Guide 5/e—I'm trying to take the example one step further and...

What's special about an ampersand in an NSUndoManager action name?

osx,cocoa,undo
I notice that if I say something like [self.undoManager setActionName: @"X & Y"]; then the resulting menu item looks like "Undo X Y" (with a double space between X and Y). (Tested on Mac OS X 10.7.5 and 10.10.3.) I can make the ampersand show up by doubling it, but...

Unexpected NSWindow becomes key window

objective-c,cocoa,nswindow,keywindow
I have a main NSWindow in my application with a button. When the button is pressed it does something like the following: NSWindow *newWindow = [NSWindow initWithContentRect:[screen frame] styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]; [newWindow makeKeyAndOrderFront:self]; [self.previousWindow orderOut:self]; This works fine most of the time, but if I have a second window open...

NSScrollView/NSCollectionView on NSVisualEffectView cause flickering

objective-c,osx,swift,cocoa,nsvisualeffectview
I have a NSCollectionView within a NSVisualEffectView within a NSPopover. Everytime when it's refreshing(add, remove, reload NSCollectionViewItem, or even just click buttons on the NSCollectionViewItem's view), it has glitches on the controls. Here's a screenshot I try to get when it's opening: It's more or less like this but only...

Cocoa Background Mode When all windows closed

objective-c,osx,cocoa
I am developing an OS X app That uses StatusBar and Also has Windows I would to move my app to "background" (That only StatusBar will be shown and windows ofc and not applications main menu) When all it's windows are closed. (I want to do it so, the app...

Detect grabbed file systemwide with coordinates and path to file

objective-c,osx,swift,cocoa
Can i detect the coordinates and pathinfo of a file / files, when the user starts to move a file somewhere? (Pressing and holding left-mouse on file) Objective-C or Swift...

Collection View Button Action (Cocoa, Xcode)

xcode,cocoa,button,collectionview
In XIB file I have a collection view which contains a button. In awake from Nib i have defined several of buttons with different images. So the application basically looks like a finder, but does not perform any actions yet. What I want to do now, is that when pressing...

NSOutletView column doesn't sort

swift,cocoa,nsoutlineview
I can't sort a NSOuletView in Mac OS X 10.10... let tableColumn = outlineView.tableColumnWithIdentifier("LocationName") println(tableColumn?.description) let sorter = NSSortDescriptor(key: "self", ascending: false) tableColumn!.sortDescriptorPrototype = sorter outlineView.reloadData() neither with the code above neither setting sorting attributes in Interface Builder. Maybe something wrong with "self"? NSOutletView column contains swift strings, compare: should...

Performance of measuring text width in AppKit

objective-c,cocoa,nsattributedstring,nslayoutmanager,nstextstorage
Is there a way in AppKit to measure the width of a large number of NSString objects(say a million) really fast? I have tried 3 different ways to do this: [NSString sizeWithAttributes:] [NSAttributedString size] NSLayoutManager (get text width instead of height) Here are some performance metrics Count\Mechanism sizeWithAttributes NSAttributedString NSLayoutManager...

Cancelling dispatch_io_read

objective-c,swift,cocoa,libdispatch
I'm parsing a very large CSV file using GCD functions (please see code below). If I encounter an error I'd like to cancel dispatch_io_read. Is there a way to do that? dispatch_io_read(channel, 0, Int.max, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0)) { (done, data, error) in guard error == 0 else { print("Read Error: \(error)")...