- 1
- 2
- 3
- 4
- 5
- 6
-(id)copyWithZone:(NSZone *)zone
{
NSString* str = [self toJSONString];
return [[MyBeautifulClass alloc] initWithJSON:str :NO];
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
0
-(id)copyWithZone:(NSZone *)zone
{
NSString* str = [self toJSONString];
return [[MyBeautifulClass alloc] initWithJSON:str :NO];
}
0
...
([dictionary stringObjectForKey:@"scale"].length > 0) ? (_scale = [dictionary stringObjectForKey:@"scale"]) : (_scale = @"1");
...
Инициализация переменной с помощью тернарной операции.
0
NSString* string = [NSString stringWithFormat:@"%li", (long)number];
NSInteger strCount = [string length] - [[string stringByReplacingOccurrencesOfString:@"1" withString:@""] length];
Считаем количество единичек в числе.
Взято отсюда: https://david-smith.org/blog/2017/07/07/a-favorite-hack/
0
NSString *categoryString;
for (Model *categoryItem in arrayCategory) {
if (categoryItem.isCheck) {
if (categoryString == nil) {
categoryString = [NSString stringWithFormat:@"%@", categoryItem.id];
} else {
categoryString = [NSString stringWithFormat:@"%@,%@", categoryString, categoryItem.id];
}
}
}
0
NSString *userName = @"username";
self.wscSession = [[[[[[[[[[[[WSCSessionBuilder create:urlString]
withConnectionDelegate:WSCSessionConnectionDelegate]
withUserName:userName]
withObserverDelegate:WSCSessionConnectionObserverDelegate]
withPackage:[[WSCCallPackage alloc] init]]
withHttpContext:httpContext]
withIceServerConfig:iceServerConfig]
build];
// Open a connection to the server...
[self.wscSession open];
https://docs.oracle.com/cd/E55119_01/doc.71/e55126/wd_iosapps.htm#WSEWD548
Оракл умеет в скобочки
P.S. Зато они сделали SIP+WS+WebRTC
0
- (NSString*) SHA256 {
const char *cStr = [self UTF8String];
unsigned char result[CC_SHA256_DIGEST_LENGTH];
CC_SHA256(cStr, strlen(cStr), result);
NSString *s = [NSString stringWithFormat:
@"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
result[0], result[1], result[2], result[3], result[4],
result[5], result[6], result[7],
result[8], result[9], result[10], result[11], result[12],
result[13], result[14], result[15],
result[16], result[17], result[18], result[19],
result[20], result[21], result[22], result[23], result[24],
result[25], result[26], result[27],
result[28], result[29], result[30], result[31]
];
return [s lowercaseString];
}
Обнаружено на самом дне
0
стретор, ау
0
~Тред о пользе багра~
Действительно, багор - очень полезная вещь. Багром можно поковыряться в жопе, чтобы извлечь застрявший обломок чьего-то члена. Помни о пользе багра.
0
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
//cell.textLabel.font = [UIFont fontWithName:@"Arial" size:10.0f];
if([indexPath row] == ((NSIndexPath*)[[tableView indexPathsForVisibleRows] lastObject]).row)
{
CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;
if (iOSDeviceScreenSize.height < 568)
{
CGRect newFrame = tableView.frame;
newFrame.size.height=iOSDeviceScreenSize.height;
tableView.frame=newFrame;
}
}
}
Autolayout своими руками
0
+ (UIView *) createTextField:(NSString *)placeholder {
UIView * view = [UIView new];
view.frame = CGRectMake(0, 0, 100, 50);
view.autoresizesSubviews = YES;
view.backgroundColor = [UIColor whiteColor];
view.layer.borderWidth = 0.5;
view.layer.borderColor = COLOR(204, 204, 204).CGColor;
view.layer.cornerRadius = 5;
view.exclusiveTouch = YES;
UITextField * testField = [UITextField new];
testField.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
testField.textColor = [UIColor blackColor];
testField.borderStyle = UITextBorderStyleNone;
testField.autocorrectionType = UITextAutocorrectionTypeNo;
[view addSubview:testField];
return view;
}
Потом у нас есть какойто контроллер
- (void)viewDidLoad {
[super viewDidLoad];
textField = [[MyClass createTextField:@"CITY, STATE OR ZIP"] subviews][0];
textField.returnKeyType = UIReturnKeySearch;
textField.delegate = (id<UITextFieldDelegate>)self;
[self.view addSubview:textField.superview];
}
На iOS 8.4 на устройстве текстфилд не будет отображаться
Нужно делать так:
UIView * v = [MyClass createTextField:@"CITY, STATE OR ZIP"];
textField = [v subviews][0];
[self.view addSubview:textField.superview];