gpt4 book ai didi

cocoa - xcode 中的 ConnectionKit 框架不适合我

转载 作者:行者123 更新时间:2023-12-03 17:37:16 25 4
gpt4 key购买 nike

我尝试制作一个连接到 ftp 服务器的 Cocoa 应用程序。所有答案都建议使用连接套件框架,但不知何故我无法使用它。当我编译框架并将其添加到我的 xcode 项目并构建它时。我无法再运行该应用程序。我在左下角收到错误消息,提示应用程序已退出,状态为 5。

解决这个问题后,现在我在尝试构建时遇到 9 个错误:(此处复制粘贴)

AppDelegate.m:17: error: 'AbstractConnection' undeclared (first use in this function)
AppDelegate.m:50: error: syntax error before 'AbstractConnection'
AppDelegate.m:55: error: 'baseDirField' undeclared here (not in a function)
AppDelegate.m:56: error: syntax error before 'if'
AppDelegate.m:62: error: syntax error before 'AbstractConnection'
AppDelegate.m:69: error: syntax error before '}' token
AppDelegate.m:71: error: syntax error before 'AbstractConnection'
AppDelegate.m:75: error: syntax error before 'for'
AppDelegate.m:75: error: syntax error before '<' token

当尝试使用以下代码时(通过谷歌找到):

//  AppDelegate.h

#import < Cocoa/Cocoa.h >

@protocol AbstractConnectionProtocol;

@interface AppDelegate : NSObject {
IBOutlet NSTextField *hostNameField;
IBOutlet NSTextField *usernameField;
IBOutlet NSTextField *passwordField;
IBOutlet NSTextField *baseDirField;
IBOutlet NSTextView *log;
IBOutlet NSTextField *status;

id <AbstractConnectionProtocol> con;

BOOL isConnected;
}

- (IBAction) connect:(id)sender;
- (IBAction) disConnect:(id)sender;

@end

// AppDelegate.m

#import "AppDelegate.h"
#import < Connection/Connection.h >

@implementation AppDelegate

- (IBAction) connect:(id)sender;
{
NSError *err = nil;
con = [[AbstractConnection connectionToHost:[hostNameField stringValue]
port:@"21"
username:[usernameField stringValue]
password:[passwordField stringValue]
error:&err] retain];
if (!con)
{
if (err)
{
[NSApp presentError:err];
}
return;
}

NSTextStorage *textStorage = [log textStorage];
[textStorage setDelegate:self]; // get notified when text changes
[con setTranscript:textStorage];

[con setDelegate:self];

[status setStringValue:[NSString stringWithFormat:@"Connecting to: %@", [hostNameField stringValue]]];
[con connect];

}

- (IBAction) disConnect:(id)sender;
{
if( con )
{
[con disconnect];
}

}
- (void)connection:(AbstractConnection *)aConn didConnectToHost:(NSString *)host
{
isConnected = YES;
[status setStringValue:[NSString stringWithFormat:@"Connected to: %@", host]];

NSString *dir = [[baseDirField stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if (dir && [dir length] > 0)
[con changeToDirectory:[baseDirField stringValue]];
[con directoryContents];

}

- (void)connection:(AbstractConnection *)aConn didDisconnectFromHost:(NSString *)host
{
isConnected = NO;
[status setStringValue:[NSString stringWithFormat:@"Disconnected from: %@", host]];

[con release];
con = nil;
}

- (void)connection:(AbstractConnection *)aConn didReceiveContents:(NSArray *)contents ofDirectory:(NSString *)dirPath
{
NSLog(@"%@ %@", NSStringFromSelector(_cmd), dirPath);
int i = 0;
for (i=0; i < [contents count]; ++i) {
id object = [contents objectAtIndex:i];
[[[log textStorage] mutableString] appendFormat:@"%@\n", object];
}
}

@end

所以我想知道我做错了什么。

最佳答案

#import < Connection/Connection.h >

尝试删除这些空格。您不太可能有一个名为“Connection”的框架,其中包含名为“Connection.h”的头文件。

关于cocoa - xcode 中的 ConnectionKit 框架不适合我,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1498756/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com