Skip to content

Instantly share code, notes, and snippets.

@rsattar
rsattar / UserNotifications.swift
Created Feb 27, 2016
Swift script that shows how to deliver notifications to OS X Notification Center using purely CLI. This can be pasted into a Playground and executed, too.
View UserNotifications.swift
import Foundation
// Create a method that will be called instead of
// "bundleIdentifier()" that returns a non-empty
// bundle id, even for a CLI script
extension NSBundle {
func fakeBundleIdentifier() -> NSString {
if self == NSBundle.mainBundle() {
return "dont.mind.me.totally.a.normal.bundleid"
} else {
@rsattar
rsattar / UserNotifications.swift
Created Feb 27, 2016
Swift script that shows how to deliver notifications to OS X Notification Center using purely CLI. This can be pasted into a Playground and executed, too.
View UserNotifications.swift
import Foundation
// Create a method that will be called instead of
// "bundleIdentifier()" that returns a non-empty
// bundle id, even for a CLI script
extension NSBundle {
func fakeBundleIdentifier() -> NSString {
if self == NSBundle.mainBundle() {
return "dont.mind.me.totally.a.normal.bundleid"
} else {
@rsattar
rsattar / Animation.md
Created Feb 8, 2016 — forked from JeOam/Animation.md
iOS Core Animation: Advanced Techniques, Part 1: The Layer Beneath
View Animation.md

1. The Layer Tree

Core Animation's original name is Layer Kit

Core Animation is a compositing engine; its job is to compose different pieces of visual content on the screen, and to do so as fast as possible. The content in question is divided into individual layers stored in a hierarchy known as the layer tree. This tree forms the underpinning for all of UIKit, and for everything that you see on the screen in an iOS application.

In UIView, tasks such as rendering, layout and animation are all managed by a Core Animation class called CALayer. The only major feature of UIView that isn’t handled by CALayer is user interaction.

There are four hierarchies, each performing a different role:

  • view hierarchy
  • layer tree
@rsattar
rsattar / LKImageView.m
Last active Jan 22, 2016
UIImageView which constraints its own height based on its layouted width
View LKImageView.m
- (void) setImage:(UIImage *)image
{
[super setImage:image];
if (self.lk_heightConstrainedToAspectWidth && self.image) {
CGFloat imageAspectRatio = self.image.size.height / self.image.size.width;
// If we haven't constrained ourself, or the constraint needs updating
if (!self.aspectRatioHeightConstraint || self.aspectRatioHeightConstraint.multiplier != imageAspectRatio) {
[self setNeedsUpdateConstraints];
}
@rsattar
rsattar / LKConfigPreview.md
Last active Nov 11, 2015
A potential way to list LKConfig keys, with potential rules
View LKConfigPreview.md

autologin = TRUE

googleLogin = TRUE

  • When version > 3.5: FALSE

barName = Hello World!

foo = FALSE

@rsattar
rsattar / SafariViewControllerAutlogin.m
Created Sep 15, 2015
SFSafariViewController autologin snippets
View SafariViewControllerAutlogin.m
// Say this is in your app delegate
- (void) attemptAutologin
{
NSURL *autologinURL = ...some..url..that..does..autologin..on..your..server
self.safariViewController = [[SFSafariViewController alloc] initWithURL:autologinURL];
self.safariViewController.modalPresentationStyle = UIModalPresentationOverFullScreen;
self.safariViewController.view.alpha = 0.0;
[self.window.rootViewController presentViewController:self.safariViewController
animated:NO
@rsattar
rsattar / SetApplicationGroupContainerIdentifier.sh
Last active Jun 27, 2017
Set ApplicationGroupContainerIdentifier in Settings.bundle to group.$(CFBundleIdentifier)
View SetApplicationGroupContainerIdentifier.sh
# Get the already-processed Info.plist, which has our bundleId, etc.
processedInfoPlistFile=$TARGET_BUILD_DIR/$INFOPLIST_PATH
# Copy the bundle identifier from our processed Info.plist
bundleId=$(/usr/libexec/PlistBuddy -c "Print :CFBundleIdentifier" "$processedInfoPlistFile")
# Prefix it with "group." to make the application group container id
appGroupContainerId=group.$bundleId
# Get the already-copied Settings.bundle/Root.plist
appPackageFolder=$TARGET_BUILD_DIR/$EXECUTABLE_FOLDER_PATH
copiedSettingsBundlePlistFile=$appPackageFolder/Settings.bundle/Root.plist
@rsattar
rsattar / Enum.m
Created Apr 29, 2015
Template for creating string <-> enum conversion
View Enum.m
// In .h
typedef NS_ENUM(NSInteger, ClusterAPIClusterMediaKind) {
ClusterAPIClusterMediaKindPhoto = 1 << 1,
ClusterAPIClusterMediaKindVideo = 1 << 2,
ClusterAPIClusterMediaKindText = 1 << 3,
ClusterAPIClusterMediaKindFancyText = 1 << 4,
ClusterAPIClusterMediaKindLocation = 1 << 5,
};
@rsattar
rsattar / CenteredTableView.m
Last active Aug 29, 2015
How to center the cells in a table view controller on iOS 7 (like Settings.app on iPad)
View CenteredTableView.m
- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
// See: http://stackoverflow.com/a/18833311/9849
if (self.displayAsCenteredTableView) {
if (tableView == self.tableView) {
CGFloat cornerRadius = 7.f;
cell.backgroundColor = UIColor.clearColor;
CAShapeLayer *fillLayer = [[CAShapeLayer alloc] init];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
CGMutablePathRef pathRef = CGPathCreateMutable();
@rsattar
rsattar / UIView+BorderViews.h
Created Dec 15, 2014
UIView+BorderViews - A simple way to add a throwaway border view to a particular edge of a UIView
View UIView+BorderViews.h
//
// UIView+BorderViews.h
// Cluster
//
// Created by Rizwan Sattar on 4/1/14.
// Copyright (c) 2014 Cluster Labs, Inc. All rights reserved.
//
#import <UIKit/UIKit.h>