Skip to content

Instantly share code, notes, and snippets.

View Koze's full-sized avatar
:octocat:
Refactoring

Koze Koze

:octocat:
Refactoring
View GitHub Profile
document.write('<link rel="stylesheet" href="https://gist-assets.github.com/assets/embed-8bf0013c72fb64f0bb1bc1872b43e39e.css">')
document.write('<div id=\"gist4325186\" class=\"gist\">\n <div class=\"gist-file\">\n <div class=\"gist-data gist-syntax\">\n \n\n\n\n <div class=\"file-data\">\n <table cellpadding=\"0\" cellspacing=\"0\" class=\"lines highlight\">\n <tr>\n <td class=\"line-numbers\">\n <span class=\"line-number\" id=\"file-gistfile1-as-L1\" rel=\"file-gistfile1-as-L1\">1<\/span>\n <span class=\"line-number\" id=\"file-gistfile1-as-L2\" rel=\"file-gistfile1-as-L2\">2<\/span>\n <span class=\"line-number\" id=\"file-gistfile1-as-L3\" rel=\"file-gistfile1-as-L3\">3<\/span>\n <span class=\"line-number\" id=\"file-gistfile1-as-L4\" rel=\"file-gistfile1-as-L4\">4<\/span>\n <span class=\"line-number\" id=\"file-gistfile1-as-L5\" rel=\"file-gistfile1-as-L5\">5<\/span>\n <span class=\"line-n
@Koze
Koze / Coments.m
Last active August 29, 2015 14:19
Fonts & Colors
#import <Founodation/Foundation.h>
// comment
/*
comment
*/
@Koze
Koze / PredicateWildcard.m
Created April 17, 2015 01:15
NSPredicate with wildcard
- (void)testWildcard1
{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF LIKE[c] 'a*e'"];
NSLog(@"%@", predicate);
// SELF LIKE[c] "a*e"
NSLog(@"%d", [predicate evaluateWithObject:@"apple"]);
// 1
NSLog(@"%d", [predicate evaluateWithObject:@"apple watch"]);
// 0
@Koze
Koze / PredicateWildcard.m
Created April 17, 2015 01:32
Predicate with wildcard vs BEGINSWITH and ENDSWITH
- (void)testWildcard3
{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF LIKE[c] 'a*a'"];
NSLog(@"%@", predicate);
// SELF LIKE[c] "a*a"
NSLog(@"%d", [predicate evaluateWithObject:@"a"]);
// 0
NSLog(@"%d", [predicate evaluateWithObject:@"aa"]);
// 1
@Koze
Koze / PredicateRegularExpression.m
Last active August 29, 2015 14:19
NSPredicate with regular expression
- (void)testRegularExpression
{
// \d+ regular expression pattern
// \\d+ pattern with escape for string
// \\\\d+ pattern with re-escape for predicate format
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES '\\d+'"];
NSLog(@"%@", predicate);
// SELF MATCHES "d+"
@Koze
Koze / PredicateUTI.m
Last active August 29, 2015 14:19
NSPredicate with UTI
- (void)testImageUTI
{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF UTI-CONFORMS-TO %@", (__bridge NSString *)kUTTypeImage];
NSLog(@"%@", predicate);
// SELF UTI-CONFORMS-TO "public.image"
NSLog(@"%d", [predicate evaluateWithObject:(__bridge NSString *)kUTTypeJPEG]);
// 1
NSLog(@"%d", [predicate evaluateWithObject:(__bridge NSString *)kUTTypePNG]);
// 1
@Koze
Koze / AppleWatchSizeCategory.m
Created April 24, 2015 22:01
preferredContentSizeCategory with Apple Watch Simulator
- (void)logSizeCategory
{
NSLog(@"%@", [WKInterfaceDevice currentDevice].preferredContentSizeCategory);
// 38mm UICTContentSizeCategoryS
// 42mm UICTContentSizeCategoryL
}
@Koze
Koze / InterfaceProperty.h
Last active August 29, 2015 14:19
interfaceProperty Property of WKInterfaceController
#import <WatchKit/WatchKit.h>
#import <Foundation/Foundation.h>
@interface InterfaceController : WKInterfaceController
@property (nonatomic) IBOutlet WKInterfaceLabel *textLabel;
@end
@Koze
Koze / UIViewController+UIViewControllerPresentation.h
Created May 9, 2015 14:07
UIViewController's dismiss method with IBAction
#import <UIKit/UIKit.h>
@interface UIViewController (UIViewControllerPresentation)
- (IBAction)dismiss:(id)sender;
@end
@Koze
Koze / class.m
Last active August 29, 2015 14:21
instance method named "class"
Class cls1 = [NSObject class];
NSLog(@"%@", NSStringFromClass(cls1));
// NSObject
NSObject *object = [[NSObject alloc] init];
Class cls2 = object.class;
NSLog(@"%@", NSStringFromClass(cls2));
// NSObject