2015-08-27 48 views
0

我通過一個聊天消息應用程序的教程工作,我在ViewController.m代碼類型,但我得到這些錯誤消息:錯誤消息「解析問題預計標識或‘(’」

預計標識或

解析文檔版本「(」

(在下面的代碼中的第一粗線)和

語義文檔版本的方法定義爲「initNetworkCommunication」不 發現

(在下面的代碼中的第2個粗線)

我怎樣才能解決這些問題?注:我使用的Xcode 6.4

#import "ViewController.h" 

@interface ViewController() 

**- (void)initNetworkCommunication; {** 
    CFReadStreamRef readStream; 
    CFWriteStreamRef writeStream; 
    CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)@ 192.168.99.2, 80, &read-Stream,&writeStream); 
    inputStream = (NSInputStream *)readStream; 
    outputStream = (NSOutputStream *)writeStream; 
    [inputStream setDelegate:self]; 
    [outputStream setDelegate:self]; 
    [inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoop-Mode]; 
    [outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode: NSDefaultRunLoop-Mode]; 
    [inputStream open]; 
    [outputStream open]; 
    [self initNetworkCommunication]; 
} 
@end 

**@implementation ViewController** 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
} 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

- (IBAction)joinChat:(id)sender { 
} 
@end 

回答

3

將此:

- (void)initNetworkCommunication; { 

此:

- (void)initNetworkCommunication { 

,並將這個:

- (void)initNetworkCommunication { 
    CFReadStreamRef readStream; 
    CFWriteStreamRef writeStream; 
    CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)@ 192.168.99.2, 80, &read-Stream,&writeStream); 
    inputStream = (NSInputStream *)readStream; 
    outputStream = (NSOutputStream *)writeStream; 
    [inputStream setDelegate:self]; 
    [outputStream setDelegate:self]; 
    [inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoop-Mode]; 
    [outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode: NSDefaultRunLoop-Mode]; 
    [inputStream open]; 
    [outputStream open]; 
    [self initNetworkCommunication]; 
} 

下面這個樣子:

@implementation ViewController 
+1

分號實際上是有效的(但毫無意義)。 – rmaddy

+0

當我應用您的建議更改時,我收到來自Xcode的錯誤3警報消息。聲明CFStreamCreatePairWithSocketToHost消息的行的第一條警告消息消息是「意外的接口名稱」NSStream':預期表達式「在聲明[inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop})的行的第二條警報消息消息是」使用未聲明的標識符「模式''以及在聲明[outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] [使用未聲明的標識符'模式'的模式')的行的第三條和最後一條警報消息。「 –

-1

你要拿出分號這行:

- (void)initNetworkCommunication; { 

它具有有隻是不正確的語法。

+1

分號實際上是有效的(無意義,但有效)。問題是在類擴展中實現方法。 – rmaddy

相關問題