Владимир Гричина (Componentix): "Не Swift`ом единым"

19
Почему не Swift

Transcript of Владимир Гричина (Componentix): "Не Swift`ом единым"

Page 1: Владимир Гричина (Componentix): "Не Swift`ом единым"

Почему не Swift

Page 2: Владимир Гричина (Componentix): "Не Swift`ом единым"
Page 3: Владимир Гричина (Componentix): "Не Swift`ом единым"

нестабильный toolchainплохая производительность toolchainсинтаксическая сольlegacy код на Objective-C

Page 4: Владимир Гричина (Componentix): "Не Swift`ом единым"

Что доступно в Objective-C?БлокиKVC Collection OperatorsNSPredicate

Page 5: Владимир Гричина (Componentix): "Не Swift`ом единым"

KVC Collection Operators

Page 6: Владимир Гричина (Componentix): "Не Swift`ом единым"

double totalPrice = 0;for (CartItem *item in self.cartItems) { totalPrice += item.price;}

vs[self.cartItems valueForKeyPath:@"@sum.price"];

Page 7: Владимир Гричина (Componentix): "Не Swift`ом единым"

Доступные операции@count, @sum, @avg, @max, @min@unionOfObjects, @distinctUnionOfObjects@unionOfArrays, @distinctUnionOfArrays, @distinctUnionOfSets

Page 8: Владимир Гричина (Componentix): "Не Swift`ом единым"

Примеры из жизни

Page 9: Владимир Гричина (Componentix): "Не Swift`ом единым"

[GNWebClient sharedInstance].selectedPlatforms = [[GNWebClient sharedInstance].platforms valueForKeyPath:@"platformId"];[GNWebClient sharedInstance].selectedSources = [[GNWebClient sharedInstance].sources valueForKeyPath:@"sourceId"];

Page 10: Владимир Гричина (Componentix): "Не Swift`ом единым"

[self preloadResources: [self.diseaseInfo valueForKeyPath: @"@distinctUnionOfArrays.allResourceURLs"]];[self preloadResources: [self.contactsMsd valueForKeyPath:@"photo"]];

Page 11: Владимир Гричина (Componentix): "Не Swift`ом единым"

int score = [[self.questions valueForKeyPath:@"@sum.currentScore"] intValue];

Page 12: Владимир Гричина (Componentix): "Не Swift`ом единым"

NSPredicateNSMutableArray *result = [NSMutableArray array];for (CartItem *item in self.cartItems) { if (item.price > 100) { [result addObject:item]; }}return [NSArray arrayWithArray:result];

vsreturn [NSArray filteredArrayWithPredicate: [NSPredicate predicateWithFormat:@"price < %@", @100]];

Page 13: Владимир Гричина (Componentix): "Не Swift`ом единым"

Доступные операцииСравнение (=, ==, >=, =>, <=, =>, <, >, !=, <>, BETWEEN)Логические операции (AND, &&, OR, ||, NOT, !)Операции со строками (BEGINSWITH, CONTAINS, ENDSWITH, LIKE,MATCHES)Операции с коллекциями (ANY, SOME, NONE, IN)Операции с массивами (array[index], array[FIRST],array[LAST], array[SIZE])

Page 14: Владимир Гричина (Componentix): "Не Swift`ом единым"

Примеры из жизни

Page 15: Владимир Гричина (Componentix): "Не Swift`ом единым"

NSArray *imageEnclosures = [self.feedItem.enclosures filteredArrayUsingPredicate: [NSPredicate predicateWithFormat:@"type like 'image/*'"]];

`

Page 16: Владимир Гричина (Componentix): "Не Swift`ом единым"

GMSAddress *address = [addressInfo.results filteredArrayUsingPredicate: [NSPredicate predicateWithFormat: @"thoroughfare MATCHES %@", @"[\\d-]+ .+"]].firstObject;

Page 17: Владимир Гричина (Componentix): "Не Swift`ом единым"

- (BOOL)mwResult{ NSArray *mandatoryQuestions = [self.allQuestions filteredArrayUsingPredicate: [NSPredicate predicateWithFormat:@"mw = %@", @"Mandatory"]]; NSArray *optionalQuestions = [self.allQuestions filteredArrayUsingPredicate: [NSPredicate predicateWithFormat:@"mw = %@", @"Optional"]];

NSPredicate *answerIsYes = [NSPredicate predicateWithFormat: @"answer = %d", QuestionAnswerYes];

NSArray *mandatoryIsYes = [mandatoryQuestions filteredArrayUsingPredicate:answerIsYes]; NSArray *optionalIsYes = [optionalQuestions filteredArrayUsingPredicate:answerIsYes]; return mandatoryIsYes.count == mandatoryQuestions.count && optionalIsYes.count > 0;}

Page 18: Владимир Гричина (Componentix): "Не Swift`ом единым"

Ваши вопросы?

Page 19: Владимир Гричина (Componentix): "Не Swift`ом единым"

Спасибо за вниманиеВладимир Гричина[email protected]