[futurebasic] Re: [FB] C Code Tester

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : June 2014 : Group Archive : Group : All Groups

From: Bernie <fblist.bw@...>
Date: Sun, 15 Jun 2014 11:31:46 +0100
Thomas Peters wrote:

> I am under impression that we need to instantiate the object first, then call a method using dot notation.
> Some kind of an example would help.


I read somewhere that calling an obj-c method using dot syntax is considered poor style. Also, I don’t think a method that takes arguments can be called that way. However, using dot notation to access instance vars (which are similar to the fields of a struct) is a bit more common. AFAIK, Swift is always dot syntax.

'---------------
include "FBLog.incl"

BeginCDeclaration
@interface MyClass : NSObject {
     BOOL flag;
}
@property (assign) BOOL flag;

- (void)saySomething:(NSString *)string;
- (void)sayHello;
@end
EndC

BeginCFunction
@implementation MyClass

@synthesize flag;

- (void)saySomething:(NSString *)string {
     NSLog(@"%@",string);
}

- (void)sayHello {
     [self saySomething:@"Hello!"];
}
@end
EndC

BeginCCode
MyClass *myClass = [[MyClass alloc] init];

[myClass sayHello];
myClass.sayHello;

//myClass.saySomething:@"Welcome to FBLog";     // error!
[myClass saySomething:@"Welcome to FBLog"];

[myClass setFlag:YES];
NSLog(@"flag = %d",[myClass flag]);

myClass.flag = NO;
NSLog(@"flag = %d",myClass.flag);
EndC

RunApplicationEventLoop()
'---------------