库文件(AppDelegate.h):
#import <Cocoa/Cocoa.h>
#import <WebKit/WebKit.h>
@interface AppDelegate : NSObject <NSApplicationDelegate>
{
@private
__unsafe_unretained NSWindow *window;
__unsafe_unretained WebView *wview;
}
@property (assign) IBOutlet NSWindow *window;
@property (assign) IBOutlet WebView *wview;
@end
在我私下添加__unsafe_unretained之前,Xcode没有编译我的代码(具有assign属性的属性'window'的现有实例变量'window'必须是__unsafe_unretained)。
主文件(AppDelegate.m):
#import "AppDelegate.h"
@implementation AppDelegate
@synthesize window;
@synthesize wview;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[[wview mainFrame]loadRequest: [NSURLRequest requestWithURL: [NSURL URLWithString: @"http://vk.com"]]];
}
- (IBAction)wview:(id)sender {
[[wview mainFrame]loadRequest: [NSURLRequest requestWithURL: [NSURL URLWithString:@"http://vk.com"]]];
}
@end