func printFonts() {
println("--- Installed fonts ---")
let families = sorted(UIFont.familyNames() as! [String]) { $0 < $1 }
for family in families {
println("family: \(family)")
let fonts = UIFont.fontNamesForFamilyName(family)
for font in fonts {
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
// Sample app to reproduce ShareLink bug from a sheet | |
// 1. Run app, tap "Present Modal Sheet" | |
// 2. Try to Share from the sheet | |
// 3. It won't present and you'll see an error in the console: | |
// Attempt to present <UIActivityViewController: 0x102820000> on <_TtGC7SwiftUI19UIHostingControllerGVS_15ModifiedContentVS_7AnyViewVS_12RootModifier__: 0x102020e00> (from <_TtGC7SwiftUI32NavigationStackHostingControllerVS_7AnyView_: 0x103829a00>) which is already presenting <_TtGC7SwiftUI29PresentationHostingControllerVS_7AnyView_: 0x10202a800>. | |
// 4. Comment out the .confirmationDialog line and it works | |
// 5. Move .confirmationDialog before .sheet and it works |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I rarely use make, probably a better way to do some/all of this? | |
SDK=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk | |
SOURCES=main.swift | |
EXECUTABLE=main | |
all: | |
swiftc -sdk $(SDK) $(SOURCES) -o $(EXECUTABLE) | |
clean: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Can currently do this | |
func titleForSection1(section: Int) -> String? { | |
switch section { | |
case 0: return "Foo" | |
case 1: return "Bar" | |
default: return nil | |
} | |
} | |
// But I want to do this to remove the redundant returns |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
// Experimental improvement to NSDictionaryOfVariableBindings where keys are simplified to remove underscores and "self." prefixes | |
// so you can use the simple version within the VFL string | |
// | |
// Example: | |
// | |
// [NSLayoutConstraint constraintsWithVisualFormat:@"|-[_foo]-[self.bar]-[baz]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_foo, self.bar, baz)]; | |
// -> this doesn't work, gives an error about "self." | |
// |
I hereby claim:
- I am zachwaugh on github.
- I am zachwaugh (https://keybase.io/zachwaugh) on keybase.
- I have a public key whose fingerprint is 6B46 CDCF BBD4 4006 97C2 0D7A 70CA 12E6 82A9 D4C6
To claim this, I am signing this object:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// static var to store shared date formatter | |
static NSDateFormatter *_formatter = nil; | |
@implementation NSDate (Extras) | |
// Simple comparison, create a string from today and date, see if they're the same | |
- (BOOL)isToday | |
{ | |
// Lazy load and cache formatter, date formatters are slow to init | |
if (!_formatter) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// [image writeToFile:[NSURL fileURLWithPath:@"/some/path/image.png"]]; | |
- (void)writeToFile:(NSURL *)fileURL | |
{ | |
NSBitmapImageRep *bitmapRep = nil; | |
for (NSImageRep *imageRep in [self representations]) | |
{ | |
if ([imageRep isKindOfClass:[NSBitmapImageRep class]]) | |
{ | |
bitmapRep = (NSBitmapImageRep *)imageRep; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (UIImage *)imageWithMask:(UIImage *)maskImage andIsWhite:(BOOL)isWhite | |
{ | |
CGRect imageRect = CGRectMake(0, 0, maskImage.size.width, maskImage.size.height); | |
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); | |
CGContextRef ctx = CGBitmapContextCreate(NULL, maskImage.size.width, maskImage.size.height, 8, 0, colorSpace, kCGImageAlphaPremultipliedLast); | |
CGContextClipToMask(ctx, imageRect, maskImage.CGImage); | |
if (isWhite) { | |
CGContextSetRGBFillColor(ctx, 1, 1, 1, 1); | |
} else { |
NewerOlder