Skip to content

Instantly share code, notes, and snippets.

@WA9ACE
Last active August 29, 2015 14:01
Show Gist options
  • Save WA9ACE/c4ea6c9e165e7271ff86 to your computer and use it in GitHub Desktop.
Save WA9ACE/c4ea6c9e165e7271ff86 to your computer and use it in GitHub Desktop.
Objective-C with comments to point out semantic syntax differences with Ruby : Part 1
//
// ICEBrain.h
//
#import <Foundation/Foundation.h>
@interface ICEBrain : NSObject
@property (nonatomic) NSString *someProperty;
- (NSString *)processMessage:(NSString *)message;
- (void)takeFirstParam:(NSString *)first andSecond:(NSString *)second;
+ (NSString *)think;
@end
//
// ICEBrain.m
//
#import "ICEBrain.h"
@implementation ICEBrain
// def processMessage(message)
- (NSString *)processMessage:(NSString *)message
{
return message;
}
// def takeFirstParam:andSecond:(first, second)
- (void)takeFirstParam:(NSString *)first andSecond:(NSString *)second
{
NSLog(@"First: %@\nSecond: %@", first, second);
}
// def self.think
+ (NSString *)think
{
return @"I'm thinking...";
}
@end
//
// main.m
//
#import <Foundation/Foundation.h>
#import "ICEBrain.h"
int main(int argc, const char * argv[]) {
@autoreleasepool {
// ICEBrain::think
[ICEBrain think];
// brain = ICEBrain.new
ICEBrain *brain = [[ICEBrain alloc] init];
// result = brain.processMessage("Hello World")
NSString *result = [brain processMessage:@"Hello World"];
// brain.takeFirstParamandSecond("first", "second")
[brain takeFirstParam:@"first" andSecond:@"second"];
// brain.someProperty = "something" with :attr_accessor
brain.someProperty = @"This is now set to this string.";
brain.someProperty // without assignment returns "This is now set to this string."
NSLog(@"%@", result);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment