Skip to content

Instantly share code, notes, and snippets.

@isthisjoe
isthisjoe / gist:5120146
Created March 8, 2013 21:45
Async'ly fetch requests on CoreData
// assume self.managedObjectContext is a main queue context
NSManagedObjectContext *backgroundContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
[backgroundContext performBlock:^{
// do your fetch - e.g. executeFetchRequest
NSManagedObjectID *objID = [someManagedObject objectID];
[self.managedObjectContext performBlock:^{
NSManagedObject *mainManagedObject = [self.managedObjectContext objectWithID:objID];
// do something now with this managed object in the main context
}];
}];
platform :ios, '5.1'
pod 'JSONKit', '~> 1.4'
pod 'Reachability', '~> 3.0.0'
pod 'AFIncrementalStore', '~> 0.3.2'
pod 'SDWebImage', '~> 3.1'
@isthisjoe
isthisjoe / gist:5178025
Last active December 15, 2015 01:09
UIRefreshControl
- (void)setupRefreshControl
{
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"Pull to refresh"];
[refreshControl addTarget:self
action:@selector(refreshControlAction:)
forControlEvents:UIControlEventValueChanged];
self.refreshControl = refreshControl;
}
@isthisjoe
isthisjoe / gist:5183886
Last active December 15, 2015 01:59
S3GetPreSignedURLRequest (100% works)
+ (NSURL*)getPreSignedURLForKey:(NSString*)key
{
AmazonS3Client *s3 = [[AmazonS3Client alloc] initWithAccessKey:kHBAmazonS3AccessKeyID withSecretKey:kHBAmazonS3SecretKey];
//Set up the request
S3GetPreSignedURLRequest * request = [[S3GetPreSignedURLRequest alloc] init];
request.bucket = kHBAmazonS3Bucket;
request.key = key;
request.expires = [NSDate dateWithTimeIntervalSinceNow:(NSTimeInterval)kHBAmazonPreSignedRequestExpireSeconds];
NSURL *url = [s3 getPreSignedURL: request];
return url;
:: Swift iOS Version Checking ::
let iOS7 = floor(NSFoundationVersionNumber) <= floor(NSFoundationVersionNumber_iOS_7_1)
let iOS8 = floor(NSFoundationVersionNumber) > floor(NSFoundationVersionNumber_iOS_7_1)
:: Replace Magic Strings with Enumerations in Swift ::
enum SegueIdentifier: String {
case OtherScreenSegue1 = "otherScreenSegue1"
case OtherScreenSegue2 = "otherScreenSegue2"
:: UIAlertController ::
let alertController = UIAlertController(title: "Default Style", message: "A standard alert.", preferredStyle: .Alert)
let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel) { (action) in
// ...
}
alertController.addAction(cancelAction)
let destroyAction = UIAlertAction(title: "Destroy", style: .Destructive) { (action) in
@isthisjoe
isthisjoe / MovieWriter.swift
Last active July 8, 2020 07:28
Swift 3 | macOs | Write NSImage(s) to a movie file. Modified from http://stackoverflow.com/a/36297656/1275125
import AppKit
import AVFoundation
class MovieWriter: NSObject {
func writeImagesAsMovie(_ allImages: [NSImage], videoPath: String, videoSize: CGSize, videoFPS: Int32) {
// Create AVAssetWriter to write video
guard let assetWriter = createAssetWriter(videoPath, size: videoSize) else {
print("Error converting images to video: AVAssetWriter not created")
return
}
@isthisjoe
isthisjoe / modular.markdown
Last active March 8, 2024 19:49
Create Xcode Modular Architecture
  1. Open Xcode. File > New > Package
    1. Select Library > Next
    2. Choose the location that will be your root folder, enter the Package name > Create
    3. Rename the module created for you to something different than the Package and Product name.
    4. Under [Package name] > Sources > [Package Name] > [Package Name].swift, replace with this SwiftUI view for later use:
import SwiftUI

public struct TestLabel: View {
 public init() {}