Cocoa Pods Cocoapods Basic Cheat Sheet
Create a Podfile
at the root of your project
platform :ios, '5.0'
pod 'AFNetworking'
pod 'OHAttributedLabel'
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) |
// 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() |
// 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 | |
} |
extension Array { | |
func first() -> Element? { | |
if isEmpty { | |
return nil | |
} | |
return self[0] | |
} | |
func last() -> Element? { |
Create a Podfile
at the root of your project
platform :ios, '5.0'
pod 'AFNetworking'
pod 'OHAttributedLabel'
#import <UIKit/UIKit.h> | |
@interface UIImageView (SGExtensions) | |
- (CGRect)sg_imageFrame; | |
@end |
#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 |
// 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] |