0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
- (void) doSomething {
<...>
if (error.code != NSURLErrorNotConnectedToInternet && error.code != NSURLErrorCancelled && error.code != NSURLErrorTimedOut) {
@synchronized (self.failedURLs) {
{
// javascript-style...
char* xcEnv = getenv("XcodeColors");
BOOL useColors = (xcEnv && !strcmp(xcEnv, "YES"));
NSString *colorWrapper;
if (useColors)
colorWrapper = @"\033[fg0,153,0;%@\033[;";
else
colorWrapper = @"%@";
void (^colorLog)(NSString *format, ...) = ^(NSString *format, ...)
{
va_list args;
va_start(args, format);
NSLog(colorWrapper, [[NSString alloc] initWithFormat:format arguments:args]);
va_end(args);
};
colorLog(@"SDWebImageManager download failed");
colorLog(@"\turl: %@", url.absoluteString);
colorLog(@"\terror: %@", [error description]);
}
[self.failedURLs addObject:url];
}
}
<...>
}
Когда очень хочется извратиться
krypt ,
01.05.2015 (Updated 29.03.2018 )
0
1
[code]<?php echo "Похоже у минусатора всего 12-13 аккаунтов, посоны плюсание 4 раза чтоб этот пост дожил до завтра" ?>[/code]
Her ,
28.04.2015 (Updated 28.03.2018 )
0
1
Какая блядина минусует все говнокоды?
Her ,
28.04.2015 (Updated 28.03.2018 )
0
1 2 3 4 5 6 7 8
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0) {
return;
} else{
self.dict[@"blahBlahBlahKey"] = @"0";
}
[self requst];
}
чудеса адгоритмизации
ep_fl ,
18.04.2015 (Updated 28.03.2018 )
0
1 2 3 4 5 6 7 8 9 10 11
#pragma mark - class methods
+ (CGFloat)cellHeightForCategory:(PostCategory *)category subscribed:(BOOL)subscribed
{
static CategoryTableViewCell *cell = nil;
if(!cell) {
cell = [[[UINib nibWithNibName:NSStringFromClass([self class]) bundle:[NSBundle mainBundle]] instantiateWithOwner:nil options:nil] firstObject];
}
[cell setupCellForCategory:category subscribed:subscribed];
[cell layoutIfNeeded];
return [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingExpandedSize].height;
}
Задаёмся мы тут вопросом, почему это таблица загрузке данных зависает на 5 секунд...
krypt ,
17.04.2015 (Updated 28.03.2018 )
0
1 2
NSDate *dateFromString = [[NSDate alloc] init];
dateFromString = [dateFormatter dateFromString:cell.textFieldCell.text];
Когда человек не знает, что делает
ep_fl ,
17.04.2015 (Updated 28.03.2018 )
0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
[self.userView sd_setImageWithURL:[comment.sender avatarThumbnailURL] placeholderImage:[UIImage coloredAvatarWithId:[NSString stringWithFormat:@"%lld", comment.sender.idValue]
andName:comment.sender.firstName
ofSize:CGSizeMake (57, 57)]];
self.dateLabel.text = [self tsFromDate:comment.createdAt];
[self.dateLabel sizeToFit];
if (comment.sender == [SWCore account])
{
self.balloonImage.image = [[UIImage imageNamed:@"in_baloon"] resizableStretchedImageWithCapInsets:UIEdgeInsetsMake (20, 50, 20, 50)];
self.messageLabel.textColor = [UIColor colorWithWhite:.4f alpha:1.0f];
self.userView.left = 20;
self.balloonImage.right = 300;
self.dateLabel.right = self.balloonImage.right;
self.dateIcon.right = self.dateLabel.left - 3;
}
else
{
self.balloonImage.image = [[UIImage imageNamed:@"out_baloon"] resizableStretchedImageWithCapInsets:UIEdgeInsetsMake (20, 50, 20, 50)];
self.messageLabel.textColor = [UIColor whiteColor];
self.userView.right = 300;
self.balloonImage.left = 20;
self.dateIcon.left = self.balloonImage.left;
self.dateLabel.left = self.dateIcon.right + 3;
}
Мастерское владение размерами
shadeapps ,
06.04.2015 (Updated 28.03.2018 )
0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = nil;
if (indexPath.row == self.titles.count - 1)
{
cell = [tableView dequeueReusableCellWithIdentifier:@"settingButtonCell" forIndexPath:indexPath];
SWSettingButtonCell *scell = (SWSettingButtonCell *) cell;
[scell.settingButton setTitleForAllStates:self.titles[indexPath.row]];
[scell.settingButton bk_removeEventHandlersForControlEvents:UIControlEventTouchUpInside];
scell.settingIcon.visible = YES;
@weakify(self);
[scell.settingButton bk_addEventHandler:^(id sender) {
[UIAlertView bk_showAlertViewWithTitle:@"Logout"
message:@"Do you want to logout?"
cancelButtonTitle:@"NO"
otherButtonTitles:@[@"YES"]
handler:^(UIAlertView *alertView, NSInteger buttonIndex) {
@strongify(self);
if (buttonIndex != 0)
{
[[SWCore instance] logout];
// fix
[SVProgressHUD show];
// end fix
}
}];
} forControlEvents:UIControlEventTouchUpInside];
}
else if (indexPath.row == self.titles.count - 2)
{
cell = [tableView dequeueReusableCellWithIdentifier:@"settingButtonCell" forIndexPath:indexPath];
SWSettingButtonCell *scell = (SWSettingButtonCell *) cell;
[scell.settingButton setTitleForAllStates:self.titles[indexPath.row]];
[scell.settingButton bk_removeEventHandlersForControlEvents:UIControlEventTouchUpInside];
scell.settingIcon.visible = NO;
@weakify(self);
[scell.settingButton bk_addEventHandler:^(id sender) {
@strongify(self);
[self performSegueWithIdentifier:@"pushSettingsSegue" sender:nil];
} forControlEvents:UIControlEventTouchUpInside];
}
else
{
cell = [tableView dequeueReusableCellWithIdentifier:@"settingCell" forIndexPath:indexPath];
SWSettingCell *scell = (SWSettingCell *) cell;
scell.settingLabel.text = self.titles[indexPath.row];
[scell.settingIcon setImage:self.icons[indexPath.row]];
switch (indexPath.row)
{
case 0:
{
scell.settingSwitch.on = [[SWCore account].settings[[NSString stringWithFormat:SETTINGS_PROFILE_VISIBILITY]] isEqualToString:SETTING_PUBLIC];
scell.settingIcon.image = scell.settingSwitch.isOn ? [UIImage imageNamed:@"settings_profile_icon_on"] : [UIImage imageNamed:@"settings_profile_icon_off"];
}
break;
case 1:
{
scell.settingSwitch.on = [[SWCore account].settings[[NSString stringWithFormat:SETTINGS_EVENTS_VISIBILITY]] isEqualToString:SETTING_PUBLIC];
scell.settingIcon.image = scell.settingSwitch.isOn ? [UIImage imageNamed:@"settings_events_button_on"] : [UIImage imageNamed:@"settings_events_button_off"];
}
break;
case 2:
{
scell.settingSwitch.on = [[SWCore account].settings[[NSString stringWithFormat:SETTINGS_PHONE_VISIBILITY]] isEqualToString:SETTING_PUBLIC];
scell.settingIcon.image = scell.settingSwitch.isOn ? [UIImage imageNamed:@"settings_phone_button_on"] : [UIImage imageNamed:@"settings_phone_button_off"];
}
break;
case 3:
{
scell.settingSwitch.on = [[SWCore account].settings[[NSString stringWithFormat:SETTINGS_PHOTOS_VISIBILITY]] isEqualToString:SETTING_PUBLIC];
scell.settingIcon.image = scell.settingSwitch.isOn ? [UIImage imageNamed:@"settings_photos_button_on"] : [UIImage imageNamed:@"settings_photos_button_off"];
}
break;
default:
break;
}
scell.settingSwitch.tag = indexPath.row;
[scell.settingSwitch bk_removeEventHandlersForControlEvents:UIControlEventValueChanged];
Один из самых классных методов cellForRowAtIndexPath что я когда-либо видел
shadeapps ,
06.04.2015 (Updated 28.03.2018 )
0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (self.mode == EventsMode)
{
SWEvent *event = [self.eventsController.dataModel itemAtIndexPath:indexPath];
static NSString *CellIdentifier = @"actionCell";
SWActionCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
[cell formatForEvent:event];
@weakify(self);
@weakify(cell);
if (![cell.actionButton_1 bk_hasEventHandlersForControlEvents:UIControlEventTouchUpInside])
{
[cell.actionButton_1 bk_addEventHandler:^(id sender) {
@strongify(cell);
SWEvent *cellEvent = cell.event;
if (cellEvent.isLikedValue)
{
[[SWCore instance] unlikeEvent:cellEvent];
}
else
{
[[SWCore instance] likeEvent:cellEvent];
}
} forControlEvents:UIControlEventTouchUpInside];
}
if (![cell.actionButton_2 bk_hasEventHandlersForControlEvents:UIControlEventTouchUpInside])
{
[cell.actionButton_2 bk_addEventHandler:^(id sender) {
@strongify(self);
@strongify(cell);
SWEvent *cellEvent = cell.event;
self.presentController = [SWMediaController controllerWithEvent:cellEvent];
[self.presentController addPhotoInController:self];
} forControlEvents:UIControlEventTouchUpInside];
}
if (![cell.actionButton_3 bk_hasEventHandlersForControlEvents:UIControlEventTouchUpInside])
{
[cell.actionButton_3 bk_addEventHandler:^(id sender) {
@strongify(self);
@strongify(cell);
SWEvent *cellEvent = cell.event;
[self performSegueWithIdentifier:@"commentsSegue" sender:cellEvent];
} forControlEvents:UIControlEventTouchUpInside];
}
if (![cell.actionButton_4 bk_hasEventHandlersForControlEvents:UIControlEventTouchUpInside])
{
[cell.actionButton_4 bk_addEventHandler:^(id sender) {
@strongify(self);
@strongify(cell);
SWEvent *cellEvent = cell.event;
self.presentController = [SWMediaController controllerWithEvent:cellEvent];
[self.presentController openPhotoBrowserInNavigationController:self.navigationController];
} forControlEvents:UIControlEventTouchUpInside];
}
if (![cell.nextButton bk_hasEventHandlersForControlEvents:UIControlEventTouchUpInside])
{
[cell.nextButton bk_addEventHandler:^(id sender) {
@strongify(self);
@strongify(cell);
SWEvent *cellEvent = cell.event;
[self performSegueWithIdentifier:@"eventControllerSegue" sender:cellEvent];
} forControlEvents:UIControlEventTouchUpInside];
}
return cell;
}
Найдено в одном чужих из проектов. Призываем экспертов по говнокоду чтобы прокомментировать неочевидные решения автора и пролить свет на тайну этого метода
shadeapps ,
06.04.2015 (Updated 28.03.2018 )
0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
if (indexPath.row == 0) {
if (![centerViewController isKindOfClass:[T7DUserInfoViewController class]]) {
T7DUserInfoViewController *userViewController = [[T7DUserInfoViewController alloc] init];
[navigationController popViewControllerAnimated:NO];
[navigationController pushViewController:userViewController animated:NO];
}
}
if (indexPath.row == 1) {
if (![centerViewController isKindOfClass:[T7DMapViewController class]]) {
T7DMapViewController *mapViewController = [[T7DMapViewController alloc] init];
[navigationController popViewControllerAnimated:NO];
[navigationController pushViewController:mapViewController animated:NO];
}
}
if (indexPath.row == 2) {
if (![centerViewController isKindOfClass:[T7DOrderListViewController class]]) {
T7DOrderListViewController *orderListViewController = [[T7DOrderListViewController alloc] init];
[navigationController popViewControllerAnimated:NO];
[navigationController pushViewController:orderListViewController animated:NO];
}
}
if (indexPath.row == 3) {
if (![centerViewController isKindOfClass:[T7DCurrentOrderViewController class]]) {
T7DCurrentOrderViewController *orderViewController = [[T7DCurrentOrderViewController alloc] init];
[orderViewController setOrderType:T7DOrderTypeCurrent];
[orderViewController setOrder:[T7DOrder currentOrder]];
[navigationController popViewControllerAnimated:NO];
[navigationController pushViewController:orderViewController animated:NO];
}
}
if (indexPath.row == 4) {
if (![centerViewController isKindOfClass:[T7DMessagesViewController class]]) {
T7DMessagesViewController *messagesViewConroller = [[T7DMessagesViewController alloc] init];
[navigationController popViewControllerAnimated:NO];
[navigationController pushViewController:messagesViewConroller animated:NO];
}
}
if (indexPath.row == 5) {
[self logout];
return;
}
Мудаки.
pr0gl ,
31.03.2015 (Updated 28.03.2018 )