Skip to content

Instantly share code, notes, and snippets.

@dimitribouniol
dimitribouniol / xcstrings.swift
Last active May 14, 2024 09:25
.xcstrings: Codable
JSONDecoder().decode([String : Localizations].self from: ...)
struct Localizations: Codable {
var localizations: [String : Localization]
}
struct Localization: Codable {
var stringUnit: StringUnit
var substitutions: [String : Substitution]
}
@dimitribouniol
dimitribouniol / AsyncDispatchQueue.swift
Created February 13, 2022 23:47
Async DispactQueue.async
extension DispatchQueue {
func async<T>(group: DispatchGroup? = nil, qos: DispatchQoS = .unspecified, flags: DispatchWorkItemFlags = [], execute work: @escaping () -> T) async -> T {
await withCheckedContinuation { continuation in
self.async(group: group, qos: qos, flags: flags) {
let result = work()
continuation.resume(returning: result)
}
}
}
}
@dimitribouniol
dimitribouniol / CommonSwiftyCrypto.swift
Created December 7, 2021 04:59
CommonSwiftyCrypto
import CommonCrypto
import Bytes // https://github.com/mochidev/Bytes
class Cryptor {
enum CryptorError: Error {
case cryptorCreationError(CCCryptorStatus)
case cryptorUpdateError(CCCryptorStatus)
case cryptorFinalizeError(CCCryptorStatus)
case cryptorResetError(CCCryptorStatus)
}
@dimitribouniol
dimitribouniol / Bump Project Version.sh
Last active December 10, 2023 02:00
Automatically Bump Versions in Xcode
cd "${PROJECT_DIR}"
# Make sure working directory is clean.
if output=$(git status --porcelain) && [ -n "$output" ]; then
echo "error: Please commit any uncommitted files before proceeding:\n$output"
exit 1
fi
# Make sure we are on master (and not a feature branch, for instance)
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
//: Playground - noun: a place where people can play
import UIKit
struct FloatRange {
var minimum: Double;
var maximum: Double;
}
var floatRange = FloatRange(minimum: 0.9999, maximum: 1.0001);
@dimitribouniol
dimitribouniol / UIView+MDConditionalAnimations.h
Last active December 14, 2015 15:08
Easily create animatable properties without needing to do the work twice when you don't want them animated!
//
// UIView+MDConditionalAnimations.h
// MDConditionalAnimations
//
// Created by Dimitri Bouniol on 3/6/13.
// Copyright (c) 2013 Dimitri Bouniol. All rights reserved.
//
#import <UIKit/UIKit.h>
@dimitribouniol
dimitribouniol / MDGraphicsFunctions.h
Last active December 14, 2015 12:18
Some simple functions to help with graphics and positioning on retina devices.
static __inline__ CGFloat MDRound(CGFloat value)
{
static CGFloat scale = 0;
if (scale <= 0) {
scale = [[UIScreen mainScreen] scale];
}
return roundf(value*scale)/scale;
}
@dimitribouniol
dimitribouniol / UIGestureRecognizer+DBTrackingAdditions.h
Created June 15, 2011 06:06
Simple property to check if a UIGestureRecognizer is tracking (like UIControl).
#import <UIKit/UIKit.h>
@interface UIGestureRecognizer (DBTrackingAdditions)
@property (nonatomic, readonly, getter=isTracking) BOOL tracking;
@end
#import <UIKit/UIKit.h>
@interface UIImage (DBMaskedImageAdditions)
- (UIImage *)maskedImageWithMask:(UIImage *)maskImage;
@end
@dimitribouniol
dimitribouniol / NSString+DBMoreStringAdditions.h
Created January 24, 2011 16:47
UIKit-based string additions for those who are going "Back to the Mac™"
#import <Cocoa/Cocoa.h>
@interface NSString (DBMoreStringAdditions)
- (CGSize)sizeWithFont:(NSFont *)aFont;
- (void)drawAtPoint:(CGPoint)point withFont:(NSFont *)aFont;
- (void)drawAtPoint:(CGPoint)point withFont:(NSFont *)aFont color:(NSColor *)aColor;
- (CGSize)sizeWithFont:(NSFont *)aFont actualFontSize:(CGFloat *)fontSize forWidth:(CGFloat)width;
- (CGSize)sizeWithFont:(NSFont *)aFont constrainedToSize:(CGSize)aSize;