Skip to content

Instantly share code, notes, and snippets.

@pgor
pgor / String+Hyphenation.swift
Last active November 12, 2024 12:12
Very basic implementation of enabling hyphenation for text.
import UIKit
public extension String {
/// Transforms this string into an NSAttributedString that has hyphenation enabled.
/// Especially at larger preferredContentSizes, regular word wrapping can lead to really
/// choppy line breaks. Hyphenating allows fuller use of the line whenever possible,
/// resulting in more text on the screen.
/// - Returns: An NSAttributedString version of this String with hyphenation enabled
func withHyphenationEnabled() -> NSAttributedString {
let paragraphStyle = NSMutableParagraphStyle()
@pgor
pgor / NSArray+Batching.h
Last active August 29, 2015 14:07
Simple category on NSArray to process it in specified batch sizes
@interface NSArray (Batching)
- (void) enumerateObjectsWithBatchSize:(NSUInteger)batchSize
usingBlock:(void (^)(NSArray* batch, NSUInteger startIndex, BOOL *stop))block;
@end
@pgor
pgor / related_counts
Created October 7, 2014 21:09
Alternative to “containers.@count == 0” predicate. Still haven't got it filtering in query, though.
@pgor
pgor / NSMutableURLRequest+CacheControl.m
Last active November 7, 2020 01:41
NSURL mechanism doesn't automatically set last-modified or etag headers, so this category does if the cache contains cached responses.
//
// NSMutableURLRequest+CacheControl.m
//
// Created by Paul Goracke on 2/26/13.
//
@implementation NSMutableURLRequest (CacheControl)
+ (instancetype) newCachePolicyRequestWithURL:(NSURL *)url timeoutInterval:(NSTimeInterval)timeoutInterval {
// If we have cached info, tell request to ignore cache because we only want to process data when we get new from server