Archive for the ‘Programming’ Category

iOS Available Fonts with Names

Tuesday, April 12th, 2016

for (NSString *familyName in [UIFont familyNames]){

NSLog(@”Family name: %@”, familyName);

for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) {

NSLog(@”–Font name: %@”, fontName);

}

}

GCD Example

Thursday, March 17th, 2016

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

// execute on thread

dispatch_async(dispatch_get_main_queue(), ^{

// execute on main thread, when thread is done

});

});

Xcode Print View Controller Hierarchy with _printHierarchy

Monday, March 14th, 2016

Run the app

Pause the app

Enter this into the Xcode console:

po [[[[UIApplication sharedApplication] keyWindow] rootViewController] _printHierarchy]

UIColor NSColorList System Colors

Sunday, March 13th, 2016

I could not find much information about NSColorList, but here is a list of RGB codes that match Xcode’s built-in colors.

extension UIColor {

class func cantaloupe() -> UIColor {
return UIColor(red:255/255, green:204/255, blue:102/255, alpha:1.0)
}
class func honeydew() -> UIColor {
return UIColor(red:204/255, green:255/255, blue:102/255, alpha:1.0)
}
class func spindrift() -> UIColor {
return UIColor(red:102/255, green:255/255, blue:204/255, alpha:1.0)
}
class func sky() -> UIColor {
return UIColor(red:102/255, green:204/255, blue:255/255, alpha:1.0)
}
class func lavender() -> UIColor {
return UIColor(red:204/255, green:102/255, blue:255/255, alpha:1.0)
}
class func carnation() -> UIColor {
return UIColor(red:255/255, green:111/255, blue:207/255, alpha:1.0)
}
class func licorice() -> UIColor {
return UIColor(red:0/255, green:0/255, blue:0/255, alpha:1.0)
}
class func snow() -> UIColor {
return UIColor(red:255/255, green:255/255, blue:255/255, alpha:1.0)
}
class func salmon() -> UIColor {
return UIColor(red:255/255, green:102/255, blue:102/255, alpha:1.0)
}
class func banana() -> UIColor {
return UIColor(red:255/255, green:255/255, blue:102/255, alpha:1.0)
}
class func flora() -> UIColor {
return UIColor(red:102/255, green:255/255, blue:102/255, alpha:1.0)
}
class func ice() -> UIColor {
return UIColor(red:102/255, green:255/255, blue:255/255, alpha:1.0)
}
class func orchid() -> UIColor {
return UIColor(red:102/255, green:102/255, blue:255/255, alpha:1.0)
}
class func bubblegum() -> UIColor {
return UIColor(red:255/255, green:102/255, blue:255/255, alpha:1.0)
}
class func lead() -> UIColor {
return UIColor(red:25/255, green:25/255, blue:25/255, alpha:1.0)
}
class func mercury() -> UIColor {
return UIColor(red:230/255, green:230/255, blue:230/255, alpha:1.0)
}
class func tangerine() -> UIColor {
return UIColor(red:255/255, green:128/255, blue:0/255, alpha:1.0)
}
class func lime() -> UIColor {
return UIColor(red:128/255, green:255/255, blue:0/255, alpha:1.0)
}
class func seafoam() -> UIColor {
return UIColor(red:0/255, green:255/255, blue:128/255, alpha:1.0)
}
class func aqua() -> UIColor {
return UIColor(red:0/255, green:128/255, blue:255/255, alpha:1.0)
}
class func grape() -> UIColor {
return UIColor(red:128/255, green:0/255, blue:255/255, alpha:1.0)
}
class func strawberry() -> UIColor {
return UIColor(red:255/255, green:0/255, blue:128/255, alpha:1.0)
}
class func tungsten() -> UIColor {
return UIColor(red:51/255, green:51/255, blue:51/255, alpha:1.0)
}
class func silver() -> UIColor {
return UIColor(red:204/255, green:204/255, blue:204/255, alpha:1.0)
}
class func maraschino() -> UIColor {
return UIColor(red:255/255, green:0/255, blue:0/255, alpha:1.0)
}
class func lemon() -> UIColor {
return UIColor(red:255/255, green:255/255, blue:0/255, alpha:1.0)
}
class func spring() -> UIColor {
return UIColor(red:0/255, green:255/255, blue:0/255, alpha:1.0)
}
class func turquoise() -> UIColor {
return UIColor(red:0/255, green:255/255, blue:255/255, alpha:1.0)
}
class func blueberry() -> UIColor {
return UIColor(red:0/255, green:0/255, blue:255/255, alpha:1.0)
}
class func magenta() -> UIColor {
return UIColor(red:255/255, green:0/255, blue:255/255, alpha:1.0)
}
class func iron() -> UIColor {
return UIColor(red:76/255, green:76/255, blue:76/255, alpha:1.0)
}
class func magnesium() -> UIColor {
return UIColor(red:179/255, green:179/255, blue:179/255, alpha:1.0)
}
class func mocha() -> UIColor {
return UIColor(red:128/255, green:64/255, blue:0/255, alpha:1.0)
}
class func fern() -> UIColor {
return UIColor(red:64/255, green:128/255, blue:0/255, alpha:1.0)
}
class func moss() -> UIColor {
return UIColor(red:0/255, green:128/255, blue:64/255, alpha:1.0)
}
class func ocean() -> UIColor {
return UIColor(red:0/255, green:64/255, blue:128/255, alpha:1.0)
}
class func eggplant() -> UIColor {
return UIColor(red:64/255, green:0/255, blue:128/255, alpha:1.0)
}
class func maroon() -> UIColor {
return UIColor(red:128/255, green:0/255, blue:64/255, alpha:1.0)
}
class func steel() -> UIColor {
return UIColor(red:102/255, green:102/255, blue:102/255, alpha:1.0)
}
class func aluminium() -> UIColor {
return UIColor(red:153/255, green:153/255, blue:153/255, alpha:1.0)
}
class func cayenne() -> UIColor {
return UIColor(red:128/255, green:0/255, blue:0/255, alpha:1.0)
}
class func asparagus() -> UIColor {
return UIColor(red:128/255, green:120/255, blue:0/255, alpha:1.0)
}
class func clover() -> UIColor {
return UIColor(red:0/255, green:128/255, blue:0/255, alpha:1.0)
}
class func teal() -> UIColor {
return UIColor(red:0/255, green:128/255, blue:128/255, alpha:1.0)
}
class func midnight() -> UIColor {
return UIColor(red:0/255, green:0/255, blue:128/255, alpha:1.0)
}
class func plum() -> UIColor {
return UIColor(red:128/255, green:0/255, blue:128/255, alpha:1.0)
}
class func tin() -> UIColor {
return UIColor(red:127/255, green:127/255, blue:127/255, alpha:1.0)
}
class func nickel() -> UIColor {
return UIColor(red:128/255, green:128/255, blue:128/255, alpha:1.0)
}

Regex for Email Address

Friday, January 22nd, 2016

– (BOOL)validateEmail:(NSString *)emailStr {

NSString *emailRegex = @”[A-Z0-9a-z._%+-]+[@][A-Za-z0-9.-]{2,}[.][A-Za-z.]{2,}”;

NSPredicate *emailTest = [NSPredicate predicateWithFormat:@”SELF MATCHES %@”, emailRegex];

return [emailTest evaluateWithObject:emailStr];

}

 

Test for email pattern
[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+.[A-Za-z.]+

barney@dino.com

barney.purple@dino.com

barney@dino.co.uk

barney.purple@dino.co.uk

barney123@dino.dinosaur

regexr.com