cocoa

LSEnvironment section of info.plist take no effects.

北战南征 提交于 2020-01-03 16:50:04
问题 I writed a dynamic library that loaded into some target applications by setting environment variable named DYLD_INSERT_LIBRARIES, the dylib load and works fine when application executed from terminal by this commands: $ export DYLD_INSERT_LIBRARIES=/path/to/mylib.dylib $ /path/to/application.app/Contents/MacOS/executable Then I set the value of DYLD_INSERT_LIBRARIES by editing LSEnvironment section in info.plist file. Some apple standard applications such as TextEdit and Calculator load my

NSTextField with auto-suggestions like Safari's address bar?

不打扰是莪最后的温柔 提交于 2020-01-03 10:45:48
问题 What's the easiest way to have an NSTextField with a "recommendation list" dynamically shown below it as the user types? Just like Safari's address bar that has a menu of some sorts (I'm pretty confident Safari's address bar suggestions is menu since it has rounded corners, blue gradient selection, and background blurring). I've tried using NSTextView's autocompletion facility but found it was inadequate: It tries to complete words instead of the whole text fields – in other words, selecting

Objective-C add functionality to every method of an object

老子叫甜甜 提交于 2020-01-03 10:20:13
问题 i want to build a small plugin-system for objects in objective-c. Now i am stuck at the point where i want to dynamically (at runtime) add a line of code to every function available in an object. I have played around with the runtime library but came to no solution, yet. What i have tried so far is this: id (^impyBlock)(id, id, ... ) = ^(id self_, id arguments, ...) { // My custom code for every function here id (*func)(__strong id,SEL,...) = (id (*)(__strong id, SEL, ...))imp; return func

How do I Increment an NSDate object in Objective-C

自闭症网瘾萝莉.ら 提交于 2020-01-03 10:19:26
问题 I want to take the next day by giving the current date The code i used as follows +(NSDate *)getForDays:(int)days fromDate:(NSDate *) date { NSTimeInterval secondsPerDay = 24 * 60 * 60 * days; return [date addTimeInterval:secondsPerDay]; } this works fine but when the daylight saving enabled this leads to errors. How can I make this work when daylight saving is enabled. 回答1: As you have found, what you have now is pretty error-prone. Not only can it trip up over a daylight savings change, but

How do I Increment an NSDate object in Objective-C

余生颓废 提交于 2020-01-03 10:18:09
问题 I want to take the next day by giving the current date The code i used as follows +(NSDate *)getForDays:(int)days fromDate:(NSDate *) date { NSTimeInterval secondsPerDay = 24 * 60 * 60 * days; return [date addTimeInterval:secondsPerDay]; } this works fine but when the daylight saving enabled this leads to errors. How can I make this work when daylight saving is enabled. 回答1: As you have found, what you have now is pretty error-prone. Not only can it trip up over a daylight savings change, but

Resized NSImageView not redrawing

梦想的初衷 提交于 2020-01-03 09:47:07
问题 I have a NSImageView which loads an image from the application bundle. It is setup as such: coverImage.image = [NSImage imageNamed:@"themeSignEnd.png"]; coverImage.imageScaling = NSImageScaleNone; coverImage.imageAlignment = NSImageAlignLeft; The image displays just fine. The size of the NSImageView is calculated based on several other factors and then set using this code: coverImage.frame = CGRectMake((1280 - 869) / 2, 0, 869 * percentage, 800); This works perfectly fine the first time it is

Use of @synthesize/@property in Objective-C inheritance

隐身守侯 提交于 2020-01-03 07:36:08
问题 If you have Class A with an instance var "foo" which has a @property/@synthesize directive, and Class B inherits from Class A, does it also need to @property/@synthesize "foo"? The reason I ask is because when I try to use Class B's "foo", the calling class says that "foo" is not something of a structured union or a member, which makes me believe it needs to be explicitly synthesized. 回答1: No, you don't. Synthesized properties are added to class A and its subclasses automatically. 回答2: If you

Separator item in NSPopupButton with bindings

天大地大妈咪最大 提交于 2020-01-03 07:21:28
问题 The contents of a NSPopupButton are bound to an NSArray of strings. How can we insert a separator item via bindings? The " - " strings (like in the olden/Classic days) doesn't work, i.e. shows up literally as a " - " menu item. Is there any out-of-the-box solution with standard Cocoa classes and bindings? This should be a trivial problem but I can't find any solution to the problem that doesn't involve silly hacks like subclassing NSMenu , NSPopupButton or other non-intuitive work arounds.

Core Data: sorting by count in a to-many relationship

倖福魔咒の 提交于 2020-01-03 07:19:14
问题 I am currently trying to setup a NSFetchedResultsController that will order my table view based on the number of entities in a to-many relationship. I am not sure if this makes a difference when counting, but this is also an inverse relationship. I thought something like this would work just fine: NSEntityDescription *entity = [NSEntityDescription entityForName:@"Parent" inManagedObjectContext:managedObjectContext]; NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:@

Adorning screenshots with NSStrings inside an NSImage

天涯浪子 提交于 2020-01-03 06:47:08
问题 I'm trying to grab a screenshot from a NSView, draw a string on top of the screenshot using the NSImage buffer then saving everything. The view grabbed from is a plain NSPanel contentview that hosts a single NSImageView. Unfortunately the output file is my string on an all black background with no sign of the screenshot. This is the code: NSImage *screenshot = [[NSImage alloc] initWithData:[mView dataWithPDFInsideRect:[mView bounds]]]; NSString *frameCounterString = @"123"; [screenshot