Skip to content

Instantly share code, notes, and snippets.

View StuartMorris0's full-sized avatar
:octocat:

Stuart Morris StuartMorris0

:octocat:
View GitHub Profile
@r-dent
r-dent / iOS Constants.swift
Last active July 9, 2016 12:06
iOS Constants Swift
let IS_iOS_7 = UIDevice.currentDevice().systemVersion.hasPrefix("7")
let IS_iOS_8 = UIDevice.currentDevice().systemVersion.hasPrefix("8")
let IS_iPad = UI_USER_INTERFACE_IDIOM() == .Pad
let IS_IPHONE = UI_USER_INTERFACE_IDIOM() == .Phone
let IS_IPHONE_4S_AND_LOWER (IS_IPHONE && max(UIScreen.mainScreen().bounds.size.height, UIScreen.mainScreen().bounds.size.width) == 480.0)
let IS_IPHONE_5 = (IS_IPHONE && max(UIScreen.mainScreen().bounds.size.height, UIScreen.mainScreen().bounds.size.width) == 568.0)
let IS_iPhone6 = (IS_IPHONE && max(UIScreen.mainScreen().bounds.size.height, UIScreen.mainScreen().bounds.size.width) == 667)
let IS_iPhone6Plus = (IS_IPHONE && max(UIScreen.mainScreen().bounds.size.height, UIScreen.mainScreen().bounds.size.width) == 736)
@bwhiteley
bwhiteley / gist:049e4bede49e71a6d2e2
Last active March 17, 2024 13:10
Initialize Swift subclass of UIView, designed in .xib
// Create CustomView.xib, set File's Owner to CustomView.
// Link the top level view in the XIB to the contentView outlet.
class CustomView : UIView {
@IBOutlet private var contentView:UIView?
// other outlets
override init(frame: CGRect) { // for using CustomView in code
super.init(frame: frame)
self.commonInit()
@prrane
prrane / ReadAddressBook.swift
Created September 4, 2014 05:34
Swift: Get contact emails from AddressBook
// based on : http://stackoverflow.com/questions/24752627/accessing-ios-address-book-with-swift-array-count-of-zero
// http://stackoverflow.com/questions/24752627/accessing-ios-address-book-with-swift-array-count-of-zero
class func extractABAddressBookRef(abRef: Unmanaged<ABAddressBookRef>!) -> ABAddressBookRef? {
if let ab = abRef {
return Unmanaged<NSObject>.fromOpaque(ab.toOpaque()).takeUnretainedValue()
}
return nil
}
@calebd
calebd / ArrayHelpers.swift
Last active November 4, 2022 15:17
Swift Helpers
extension Array {
func first() -> Element? {
if isEmpty {
return nil
}
return self[0]
}
func last() -> Element? {
@StuartMorris0
StuartMorris0 / CocoaPodsCheatSheet.md
Last active December 26, 2015 02:49
CocoaPods Cheat Sheet

Cocoa Pods Cocoapods Basic Cheat Sheet

Create a Podfile at the root of your project

platform :ios, '5.0'

pod 'AFNetworking'
pod 'OHAttributedLabel'
@justin
justin / UIImageView+ImageFrame.h
Created February 18, 2013 19:27
Category to get the frame of an image that's inside a UIImageView. Since I use aspect fit on some stuff, I sometimes need to account for the top and bottom borders.
#import <UIKit/UIKit.h>
@interface UIImageView (SGExtensions)
- (CGRect)sg_imageFrame;
@end
@numo16
numo16 / Macros.h
Created August 20, 2012 20:38
Some useful iOS/Objective-C Macros
#define ApplicationDelegate ((AppDelegate *)[[UIApplication sharedApplication] delegate])
#define UserDefaults [NSUserDefaults standardUserDefaults]
#define NotificationCenter [NSNotificationCenter defaultCenter]
#define SharedApplication [UIApplication sharedApplication]
#define Bundle [NSBundle mainBundle]
#define MainScreen [UIScreen mainScreen]
#define ShowNetworkActivityIndicator() [UIApplication sharedApplication].networkActivityIndicatorVisible = YES
#define HideNetworkActivityIndicator() [UIApplication sharedApplication].networkActivityIndicatorVisible = NO
#define NetworkActivityIndicatorVisible(x) [UIApplication sharedApplication].networkActivityIndicatorVisible = x
#define NavBar self.navigationController.navigationBar
@icleversoft
icleversoft / iosMacros.h
Last active August 3, 2016 07:01
iOS Macros
// App Information
#define AppName [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"]
#define AppVersion [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]
#define AppDelegate(type) ((type *)[[UIApplication sharedApplication] delegate])
#define NSAppDelegate(type) ((type *)[[NSApplication sharedApplication] delegate])
#define SharedApp [UIApplication sharedApplication]
#define NSSharedApp [NSApplication sharedApplication]
#define Bundle [NSBundle mainBundle]
#define MainScreen [UIScreen mainScreen]
@mikejolley
mikejolley / gist:2044101
Last active May 18, 2021 17:02
WooCommerce - Show number of items in cart and total
<a class="cart-contents" href="<?php echo wc_get_cart_url(); ?>" title="<?php _e( 'View your shopping cart' ); ?>"><?php echo sprintf ( _n( '%d item', '%d items', WC()->cart->get_cart_contents_count() ), WC()->cart->get_cart_contents_count() ); ?> - <?php echo WC()->cart->get_cart_total(); ?></a>