Tuesday, December 31, 2013

Reach pen a letter to the financial questions, seek answers, we can discuss the next

MAC development positions
Topic 1.
Please briefly Cocoa role in NSWindowController class.

Topic 2.
Please use Objective-C to achieve a section of code NSString string into the clipboard, and add notes in Chinese.

Topic 3.
Please Objcetive-C module to achieve access to the currently running path, and add Chinese comments.



Reply:
Is mac development.
Reply:
Give answers,
received onlineQuestion 1: NSWindowController class role.
Answer: NSWindowController and NSDocumentController and NSDocument class together to create a document-based application defines a framework,
I think it is equivalent to the MFC view class, on one hand, the data will be presented in the document, on the other hand is responsible for conversation between the user interface program.

Question 2: the string on the clipboard program
Answer:
/ / Define header file
MyPasteboardTest.h
# Import
@ Interface MyPasteboardTest: NSObject {

NSString * Mystr; / / member variables, save the clipboard to be pasted into a string
}
/ / Initialization function
- (Void) init;
/ / Variable functions, member variables Mystr
filled with m_str- (Void) SetStr: (NSString *) m_str;
/ / Write clipboard function
- (BOOL) WriteToPasteboard: (NSPasteboard *) pasteboard;
@ End
/ /. M implementation file
MyPasteboardTest.m
# Import "MyPasteboardTest.h"
@ Implementation MyPasteboardTest
- (Void) init
{
Mystr = nil ;/ / initialized to empty
}
- (Void) SetStr: (NSString *) m_str
{
Mystr = m_str;
}
- (BOOL) WriteToPasteboard: (NSPasteboard *) pasteboard / / write string to the clipboard function
{
[Pasteboard declareTypes: [NSArray arrayWithObject: NSStringPboardType]
owner: self];
[Pasteboard setString: Mystr forType: NSStringPboardType];
}
Therefore, to the string into the clipboard, you can first call SetStr function set to paste the contents,
You can then call WriteToPasteboard function.

3, to get the current running module path
- (NSString *) GetModulePath
{
NSFileManager * fileManager = [NSFileManager defaultManager]; / / Create a file manager
NSString * path = [fileManager currentDirectoryPath] ;/ / call currentDirectoryPath method NSFileManager / / class with fileManager object acquisition path
NSLog (@ "% @", path); / / The path string is displayed in the terminal
}

No comments:

Post a Comment