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
// Based on https://gist.github.com/schickling/b5d86cb070130f80bb40#gistcomment-2894406 | |
func image(data: Data, orientation: UIImage.Orientation = .up) -> UIImage? { | |
let context: CGContext | |
let width: CGFloat | |
let height: CGFloat | |
func defaultImage() -> UIImage? { | |
return UIImage(data: data) | |
} |
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
/* | |
File: KeychainItemWrapper.h | |
Abstract: | |
Objective-C wrapper for accessing a single keychain item. | |
Version: 1.2 - ARCified | |
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple | |
Inc. ("Apple") in consideration of your agreement to the following | |
terms, and your use, installation, modification or redistribution of |
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
enum SPErrors: Error { | |
case inputStringWasEmpty | |
} | |
struct StringPublisher: Publisher { | |
typealias Output = [Character] | |
typealias Failure = Error | |
private let data: [Character] |
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
// | |
// Asymmetric.swift | |
// | |
// Created by David Hoerl on 12/23/18. | |
// Copyright © 2018 David Hoerl. All rights reserved. | |
// | |
/* | |
This is the portion you need in the distributed app, which uses the public key that can appear in plain text | |
*/ |
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
When I posted this on Apple’s Cocoadev listserver, I never did get pointers to code to convert a NSDictionary to a binary formatted plist, but did get pointers to look at NSPropertyListSerialization - something I had already (mis)read a few times. | |
The description for the dataFromPropertyList class method seems confusing if you don't understand that you can create a property list with no keys: that is, you can create one with a single compliant object, and the key becomes "root". | |
So, in the unlikely event that some else someday has the same mental block, here is actual tested code that takes a NSDictionary and creates a binary plist file: | |
NSDictionary *dict; | |
char *payload = "This is the payload"; | |
dict = [NSDictionary dictionaryWithObjectsAndKeys: |
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
struct UpperCasePublisher: Publisher { | |
typealias Output = [Character] | |
typealias Failure = Error | |
let upstreamPublisher: AnyPublisher<Output, Error> | |
init(upstream: AnyPublisher<Output, Error>) { | |
self.upstreamPublisher = upstream | |
} |
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
final class StringSubscriber: Subscriber { | |
typealias Input = [Character] | |
typealias Failure = Error | |
var subscription: Subscription? | |
var count = 0 | |
func receive(subscription: Subscription) { | |
self.subscription = subscription | |
self.subscription?.request(.max(1)) |
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
// Inspired by https://gist.github.com/nitrag/b3117a4b6b8e89fdbc12b98029cf98f8 | |
+ (UIImage *)imageFromView:(UIView *)view subsection:(CGRect)subRect | |
{ | |
// Image will be sized to the smaller rectangle | |
UIGraphicsBeginImageContextWithOptions(subRect.size, YES, 0); | |
// The primary view needs to shift up and left so the desired rect is visible | |
// But the rect passed below needs to be sized to the view, otherwise the image is compressed | |
CGRect drawRect = CGRectMake(-subRect.origin.x, -subRect.origin.x, view.bounds.size.width, view.bounds.size.height); |
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 NSString *kcIdentifier = @"MyApp"; | |
@implementation LTAppDelegate (KeyChain) | |
- (void)keychainInit | |
{ | |
self.keychainDict = [NSMutableDictionary dictionaryWithCapacity:7]; | |
KeychainItemWrapper *item = [[KeychainItemWrapper alloc] initWithIdentifier:kcIdentifier accessGroup:nil]; | |
[self.keychainDict setObject:@"" forKey:kcEmailAddress]; |
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
- (uint64_t)freeDiskspace | |
{ | |
uint64_t totalFreeSpace = 0; | |
__autoreleasing NSError *error = nil; | |
NSString *path = [self applicationDocumentsDirectory]; | |
NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:path error: &error]; | |
if (dictionary) { | |
NSNumber *freeFileSystemSizeInBytes = [dictionary objectForKey:NSFileSystemFreeSize]; |
NewerOlder