Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(225)

Side by Side Diff: docs/cocoa_tips_and_tricks.md

Issue 1309473002: WIP: Migrate Wiki content over to src/docs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « docs/closure_compilation.md ('k') | docs/code_coverage.md » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Introduction
2
3 A collection of idioms that we use when writing the Cocoa views and controllers for Chromium.
4
5 ## NSWindowController Initialization
6
7 To make sure that |window| and |delegate| are wired up correctly in your xib, it 's useful to add this to your window controller:
8
9 ```
10 - (void)awakeFromNib {
11 DCHECK([self window]);
12 DCHECK_EQ(self, [[self window] delegate]);
13 }
14 ```
15
16 ## NSWindowController Cleanup
17
18 "You want the window controller to release itself it |-windowDidClose:|, because else it could die while its views are still around. if it (auto)releases itself in the callback, the window and its views are already gone and they won't send messages to the released controller."
19 - Nico Weber (thakis@)
20
21 See [Window Closing Behavior, ADC Reference](http://developer.apple.com/mac/libr ary/documentation/Cocoa/Conceptual/Documents/Concepts/WindowClosingBehav.html#// apple_ref/doc/uid/20000027) for the full story.
22
23 What this means in practice is:
24
25 ```
26 @interface MyWindowController : NSWindowController<NSWindowDelegate> {
27 IBOutlet NSButton* closeButton_;
28 }
29 - (IBAction)closeButton:(id)sender;
30 @end
31
32 @implementation MyWindowController
33 - (id)init {
34 if ((self = [super initWithWindowNibName:@"MyWindow" ofType:@"nib"])) {
35 }
36 return self;
37 }
38
39 - (void)awakeFromNib {
40 // Check that we set the window and its delegate in the XIB.
41 DCHECK([self window]);
42 DCHECK_EQ(self, [[self window] delegate]);
43 }
44
45 // NSWindowDelegate notification.
46 - (void)windowWillClose:(NSNotification*)notif {
47 [self autorelease];
48 }
49
50 // Action for a button that lets the user close the window.
51 - (IBAction)closeButton:(id)sender {
52 // We clean ourselves up after the window has closed.
53 [self close];
54 }
55 @end
56 ```
57
58 ## Unit Tests
59
60 There are four Chromium-specific GTest macros for writing ObjC++ test cases. Th ese macros are EXPECT\_NSEQ, EXPECT\_NSNE, and ASSERT variants by the same names . These test `-[id<NSObject> isEqual:]` and will print the object's `-descripti on` in GTest-style if the assertion fails. These macros are defined in //testin g/gtest\_mac.h. Just include that file and you can start using them.
61
62 This allows you to write this:
63 ```
64 EXPECT_NSEQ(@"foo", aString);
65 ```
66 Instead of this:
67 ```
68 EXPECT_TRUE([aString isEqualToString:@"foo"]);
69 ```
OLDNEW
« no previous file with comments | « docs/closure_compilation.md ('k') | docs/code_coverage.md » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698