This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)customKeyboardOnSearchBar:(UISearchBar *)searchBar | |
{ | |
for(UIView *subView in searchBar.subviews) { | |
if([subView conformsToProtocol:@protocol(UITextInputTraits)]) { | |
[(UITextField *)subView setKeyboardAppearance:UIKeyboardAppearanceAlert]; | |
[(UITextField *)subView setReturnKeyType:UIReturnKeyDone]; | |
} else { | |
for(UIView *subSubView in [subView subviews]) { | |
if([subSubView conformsToProtocol:@protocol(UITextInputTraits)]) { | |
[(UITextField *)subSubView setReturnKeyType:UIReturnKeyDone]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSString *)mostCommonCharacter:(NSString *)string | |
{ | |
__block NSMutableArray *charIndex = [[NSMutableArray alloc] init]; | |
// Enumerate | |
[string enumerateSubstringsInRange:NSMakeRange(0, string.length) options:NSStringEnumerationByComposedCharacterSequences usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) | |
{ | |
[charIndex addObject:substring]; | |
}]; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)resizeToFitSubviews:(UIView *)view | |
{ | |
float w, h; | |
for (UIView *v in view.subviews) { | |
float fw = v.frame.origin.x + v.frame.size.width; | |
float fh = v.frame.origin.y + v.frame.size.height; | |
w = MAX(fw, w); | |
h = MAX(fh, h); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)openThisURL:(NSString *)launchUrl withFallback:(NSString *)fallback | |
{ | |
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:launchUrl]]) { | |
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:launchUrl]]; | |
} else { | |
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:fallback]]; | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
var names = ["Luis", "Hector", "Selena", "Emmanuel", "Amish", "Rawle"] | |
var firsts = [String: String]() | |
var lasts = [String: String]() | |
var output = [String]() | |
for name in names { | |
var key = (name as NSString).substringFromIndex(name.utf16Count-1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
var numbers = [7, 7, 7, 1, 1, 1, 2, 3, 4, 4, 5, 5, 6, 7, 7, 8, 8] | |
var filter = [Int]() | |
for number in numbers { | |
if !contains(filter, number) { | |
filter.append(number) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
var namesA = ["Luis", "Hector", "Selena", "Emmanuel", "Amish", "Rawle", "Selena"] | |
var namesB = ["Luis", "Selena", "Amish", "Rawle", "George", "Heberti"] | |
var filter = [String]() | |
for item in namesA+namesB { | |
if !contains(filter, item) { | |
filter.append(item) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
let a = [1, 2, 3, 4, 5, 6, 7, 50, 30] | |
let b = [3, 10, 5, 6, 7, 8, 9, 51, 1] | |
var filter = [Int]() | |
for number in a { | |
if !contains(b, number) { | |
filter.append(number) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
var words = ["Cat", "Cot", "Brazil", "Cut", "cat", "Apple", "Watch"] | |
var filter = [String]() | |
for word in words { | |
if let match = word.rangeOfString("(C|c)(.*)t", options: .RegularExpressionSearch) { | |
filter.append(word) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
var str = "aaaabbbaaaa * bbbb b bbbbbbb ccccccccdd ddddddd dddd" | |
var cnt = [String: Int]() | |
var i = 0 | |
for char in str { | |
var c = String(char) | |
if let match = cnt[c] { |
OlderNewer