cocoa

Programmatically put a Mac into sleep

孤人 提交于 2020-01-11 19:56:42
问题 I can't find any instructions how to put a Mac programmatically into sleep mode (in Objective-C). I'm sure it should be only one line, but could you give me a hint? 回答1: #include <stdio.h> #include <CoreServices/CoreServices.h> #include <Carbon/Carbon.h> SendAppleEventToSystemProcess(kAESleep); OSStatus SendAppleEventToSystemProcess(AEEventID EventToSend) { AEAddressDesc targetDesc; static const ProcessSerialNumber kPSNOfSystemProcess = { 0, kSystemProcess }; AppleEvent eventReply = {typeNull

Programmatically put a Mac into sleep

孤街浪徒 提交于 2020-01-11 19:56:08
问题 I can't find any instructions how to put a Mac programmatically into sleep mode (in Objective-C). I'm sure it should be only one line, but could you give me a hint? 回答1: #include <stdio.h> #include <CoreServices/CoreServices.h> #include <Carbon/Carbon.h> SendAppleEventToSystemProcess(kAESleep); OSStatus SendAppleEventToSystemProcess(AEEventID EventToSend) { AEAddressDesc targetDesc; static const ProcessSerialNumber kPSNOfSystemProcess = { 0, kSystemProcess }; AppleEvent eventReply = {typeNull

Private data sharing using CloudKit

三世轮回 提交于 2020-01-11 18:54:13
问题 Is there a straightforward way to share private data between two or more users using CloudKit? Public and private date are obvious, but there doesn't seem to be a way to allow a group of users to organize their own silo to share data amongst themselves without making it available to all the other users of the system and to the app developer. I have an academic collaboration app in mind but the simplest example would be private messaging between two users. I guess one could try to build a

NSImage doesn't scale

守給你的承諾、 提交于 2020-01-11 18:35:51
问题 I'm developing a quick app in which I have a method that should rescale a @2x image to a regular one. The problem is that it doesn't :( Why? -(BOOL)createNormalImage:(NSString*)inputRetinaImagePath { NSImage *inputRetinaImage = [[NSImage alloc] initWithContentsOfFile:inputRetinaImagePath]; NSSize size = NSZeroSize; size.width = inputRetinaImage.size.width*0.5; size.height = inputRetinaImage.size.height*0.5; [inputRetinaImage setSize:size]; NSLog(@"%f",inputRetinaImage.size.height);

What is NSBundle and mainBundle in objective C?

北城以北 提交于 2020-01-11 16:47:30
问题 I want to ask a question about the objective C on iPhone application. I read some sample program in the apple developer website and I found that almost all of the applications contains a word called 'NSBundle' and 'mainBundle', and I really don't understand the meaning of this word. Can anyone tell me about that? Thank you very much. 回答1: A bundle is a structure used for packaging software on Mac OS X. Applications, frameworks and plug-ins are all different kinds of bundles. Bundles may

What is NSBundle and mainBundle in objective C?

≡放荡痞女 提交于 2020-01-11 16:46:22
问题 I want to ask a question about the objective C on iPhone application. I read some sample program in the apple developer website and I found that almost all of the applications contains a word called 'NSBundle' and 'mainBundle', and I really don't understand the meaning of this word. Can anyone tell me about that? Thank you very much. 回答1: A bundle is a structure used for packaging software on Mac OS X. Applications, frameworks and plug-ins are all different kinds of bundles. Bundles may

Automatically grow document view of NSScrollView using auto layout?

随声附和 提交于 2020-01-11 15:39:08
问题 Is there a simple way to get an NSScrollView to adapt to its document view changing size when using auto layout? I have tried to call both setNeedsUpdateConstraints: and setNeedsLayout: on the document view, the clip view and the scroll view, without any results. fittingSize of the document view reports the correct size. The problem is that the document view, which holds subviews, is not re-sized when the subviews change their size, even if they call invalidateIntrinsicContentSize . The

How to get the OS X system version?

霸气de小男生 提交于 2020-01-11 15:37:36
问题 I want to get the OS X system version, such as: 10.5.4, 10.4.8, etc. I want to get it in my app, how do I do this? Thanks! 回答1: You can read the property list at "/System/Library/CoreServices/SystemVersion.plist and extract the "ProductVersion" key, this is how the OS X installer application does it. Here's an example: NSString *versionString; NSDictionary * sv = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"]; versionString = [sv objectForKey:@

UISwitch, something similar for Mac?

我的梦境 提交于 2020-01-11 15:30:25
问题 Im sure most of you are familiar with the UISwitch on iOS. Is their any existing project trying to implement something like this on Mac? If not, where would one start to make one? I see them frequently and can think of so many uses. Thanks in advance 回答1: I've used the Mondo Switch that's part of the Cocoa Mondo Kit. It works pretty well. 回答2: I think you should use NSCheckBox since it is the equivalent on a computer where you use a mouse and not your finger. 回答3: I recently extended Peter

Problem copying NSMutableArray

泪湿孤枕 提交于 2020-01-11 13:37:19
问题 I am trying to copy one array to another: NSMutableArray *itemsCopy = [[NSMutableArray alloc] initWithArray:self.items copyItems:YES]; but I get the error: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Item copyWithZone:]: unrecognized selector sent to instance 0x5a74900' *** Call stack at first throw: ( 0 CoreFoundation 0x025afc99 __exceptionPreprocess + 185 1 libobjc.A.dylib 0x026fd5de objc_exception_throw + 47 2 CoreFoundation 0x025b17ab -[NSObject