Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
Во-первых, в Eero для выделения блоков вместо фигурных скобок используются отступы, как в Python или Ruby.
@interface TestObject : NSObject
{
int test;
}
@property (nonatomic, assign, getter = getTest) int test;
@end
@implementation TestObject
@synthesize test;
- (id) init
{
if (self = [super init])
{
NSLog(@"test %d %d", self->test, self.test);
}
return self;
}
- (int) getTest
{
NSLog(@"getter");
return 1;
}
@endinterface TestObject
int test {nonatomic}
end
implementation TestObject
int _test
init, return instancetype = self
if (self = super.init)
Log('test %d %d', _test, self.test);
test, return int = 1
Log('getter');
end
counter := 0
if isReady
counter := 0 // compiler error
- (int) test переименовать.BOOL status = NO;
if (!status && <длинное условие>)
status = YES;
if (!status && <второе длинное условие>)
status = YES;
if (!status && <третье длинное условие>)
status = YES;
BOOL status = NO;
if(cond){
BOOL status = YES;
...
}
let n = n+1 in ... надо давать новое имя let n1 = n+1 in ...case n+1 in n -> ... но уж больно многословно получается.BOOL status = NO;
if (...){
BOOL status = YES;
}
for int i in 0 .. 10 и прочее. Т.е. дело не только в синтаксисе.name, return String = 'Macintosh'
format, return String = 'HFS+'
Мне очень нравятся квадратные скобки
int death = [NSBox boxWithBear:[NSBear bearWithDuck:[NSDuck duckWithEggs:[NSEgg eggWithNiddle:[NSNiddle alloc] init]]]];
int death = NSBox.boxWithBear(NSBear.bearWithDuck(NSDuck.duckWithEggs(NSEgg.eggWithNiddle(new NSNiddle))));
[NSEgg eggWithNiddle:[NSNiddle alloc] init]
@protocol NSContaining <NSObject>
-(instancetype)initWith:(id)content;
-(instancetype)initWith:(id)content and:(id)anotherContent;
@end
@interface NSBear : NSObject <NSContaining> @end
@interface NSDuck : NSObject <NSContaining> @end
@interface NSEgg : NSObject <NSContaining> @end
[[NSBear alloc] initWith:[[NSDuck alloc] initWith:[[NSEgg alloc] initWith:[[NSNeedle alloc] init]]] and:[[NSEgg alloc] init]];
[[NSBear alloc] initWith:[[NSDuck alloc] initWith:[[NSEgg alloc] initWith:[[NSNeedle alloc] init]] and:[[NSEgg alloc] init]]];
[[NSBear alloc] initWith:[[NSDuck alloc] initWith:[[NSEgg alloc] initWith:[[NSNeedle alloc] init] and:[[NSEgg alloc] init]]]];
[NSBear.alloc initWith:[NSDuck.alloc initWith:[NSEgg.alloc initWith:NSNeedle.alloc.init]] and:NSEgg.alloc.init];
[NSBear.alloc initWith:[NSDuck.alloc initWith:[NSEgg.alloc initWith:NSNeedle.alloc.init] and:NSEgg.alloc.init]];
[NSBear.alloc initWith:[NSDuck.alloc initWith:[NSEgg.alloc initWith:NSNeedle.alloc.init and:NSEgg.alloc.init]]];
initWithDuck:(NSDuck*)duck NSBear *bear = [[NSBear alloc] initWithDuck:[[NSDuck alloc] initWithEgg:[[NSEgg alloc] initWithNeedle:[[NSNeedle alloc] init]]]
egg:[[NSEgg alloc] init]];
NSBear *bear = [[NSBear alloc] initWithDuck:[[NSDuck alloc] initWithEgg:[[NSEgg alloc] initWithNeedle:[[NSNeedle alloc] init]]
secondEgg:[[NSEgg alloc] init]]];
NSBear *bear = [[NSBear alloc] initWithDuck:[[NSDuck alloc] initWithEgg:[[NSEgg alloc] initWithNeedle:[[NSNeedle alloc] init]
egg:[[NSEgg alloc] init]]]];
Практически не использую, кстати.
ДиректорВасильев {ЗаместительКрючков; ЗаместительСвязнов}
ЗаместительКрючков {ДиректорВасильев; НачальникОтделаКадровПучков; НачальникОтделаФинансовТранжиров}
...
умышленная ошибка
[obj makeBoxWithOrigin: origin andSize: size];
obj.makeBoxWithOrigin(origin, andSize: size)
obj.makeBoxWithOrigin: origin, andSize: size
@interface CustomView : UIView
@property (copy) NSString *text;
@end
@implementation CustomView
- (id) initWithFrame:(CGRect)frame {
[super initWithFrame:frame];
self.text = @"";
return self;
}
- (id) initWithText:(NSString*)text {
UIFont *font = [UIFont systemFontOfSize:12];
CGRect size = [text sizeWithFont:font];
// skip local initializer
[super initWithFrame:{{0, 0}, size}];
self.text = text;
return self;
}
@end
class CustomView < UIView
alias :'super_initWithFrame:' :'initWithFrame:'
def initWithFrame(frame)
super.tap do
@text = ''
end
end
def initWithText(text)
font = UIFont.systemFontOfSize(12)
size = text.sizeWithFont(font)
super_initWithFrame([[0, 0], size]).tap do
@text = text
end
end
end
interface CustomView : UIView
String text {copy}
end
implementation CustomView
initWithFrame:CGRect, return instancetype = self
if (self = super.initWithFrame: frame)
self.text = ''
initWithText:String, return instancetype = self
font := UIFont.systemFontOfSize: 12
size := text.sizeWithFont: font
CGRect rect = {{0, 0}, size}
if (self = super.initWithFrame:rect)
self.text = ''
end
...
m_pLockedData = new unsigned char[memoryRequired];
ComputeVertexDescription(m_pLockedData + m_FirstUnwrittenOffset);
desc.m_nFirstVertex = 0;
desc.m_nOffset = m_FirstUnwrittenOffset;
return true;
fail:
ComputeVertexDescription(NULL, 0, desc);
desc.m_nFirstVertex = 0;
desc.m_nOffset = 0;
return false;
...
return handle;
fail_plink:
glDeleteProgram(program);
fail_pcreate:
glDeleteShader(pixelShader);
fail_ps:
glDeleteShader(vertexShader);
fail_init:
return SHADER_PROGRAM_HANDLE_INVALID;
openFile String, [withPermissions: String], return FileHandleFileHandle openFile(String, [withPermissions: String])handle = FileHandle.fileHandleForReadingAtPath(file)typedef id(^FileHandleFactoryBlock)(NSString *);
@interface FileHandle : NSObject
+(instancetype)fileHandleForReadingAtPath:(NSString *)path;
+(FileHandleFactoryBlock)fileHandleForReadingAtPath;
@end
FileHandle.fileHandleForReadingAtPath(file) ? Будут отослано сообщение fileHandleForReadingAtPath: с одним аргументом или fileHandleForReadingAtPath без аргументов с последующим вызовом полученного блока?stringArray := (String<MutableArray>)MutableArray.new
stringArray.addObject: '123'
stringArray.addObject: @13 // Warning: incompatible pointer type
numArray := (Number<MutableArray>)MutableArray.new
numArray.addObject: @13
numArray.addObject: 'ABC' // Warning: incompatible pointer type
Eero — Objective-C без скобочек