This file contains hidden or 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
| struct HelloWorld{ | |
| static func hello( _ input:String = "World") -> String{ | |
| return "Hello, \(input)!" | |
| } | |
| } |
This file contains hidden or 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
| func presentCameraFromFirstViewController(sender: AnyObject){ | |
| let storyboard = UIStoryboard(name: "Main", bundle: nil) | |
| let vc = storyboard?.instantiateViewControllerWithIdentifier("MasterNavigation") as! UINavigationController | |
| let vc1 = (storyboard?.instantiateViewControllerWithIdentifier("TabBarViewController") as! UITabBarController).viewControllers | |
| let vc2 = vc1?.first as! UINavigationController | |
| presentViewController(vc, animated: true, completion: nil) | |
| } |
This file contains hidden or 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
| func splitAtCamelCase(inString: String, var result:[String] = []) -> [String] { | |
| var previousLetter:String = "" | |
| var lastSplitIndex = 0 | |
| if !inString.isEmpty { previousLetter = inString.characters.first.map{String($0)} ?? "" } | |
| for (index, currentLetter) in inString.characters.map({String($0)}).enumerate(){ | |
| if previousLetter.isLowercase && currentLetter.isUppercase{ | |
| let rangeWord = Range<Int>(start: lastSplitIndex, end: index) | |
| result.append(inString.substringWithRangeInt(rangeWord)) | |
| lastSplitIndex = index | |
| } |
This file contains hidden or 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
| func splitStringToArray(inString:String) -> [String]{ | |
| return inString.characters.split(isSeparator: { splitAt($0) }).map{String($0)} | |
| } | |
| func splitAt(characterToCompare:Character, charToSplitAt:String = " !&$%^&,:")-> Bool{ | |
| for each in charToSplitAt.characters{ | |
| if each == characterToCompare{ | |
| return true | |
| } |
This file contains hidden or 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
| private extension String { | |
| func trimWhiteSpace()-> String{ | |
| let removeSpaces = trimCharacters(" ", sourceText: self) | |
| if removeSpaces.hasSuffix("\n"){ | |
| return String(removeSpaces.characters.dropLast()) | |
| } | |
| return removeSpaces | |
| } |
This file contains hidden or 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 Darwin | |
| extension tm{ | |
| var year:Int32 { return tm_year + 1900 } | |
| var month:Int32 { return tm_mon + 1 } | |
| var day:Int32 { return tm_mday } | |
This file contains hidden or 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
| // use this extension | |
| //https://gist.github.com/masters3d/b90a99aac6b923add0ee | |
| import Darwin | |
| var date0 = tm() | |
| var chars = asctime(&date0) | |
| var toReturnString = "" | |
| while chars.successor().memory != 0 { |
This file contains hidden or 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
| let weekday = ["", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] | |
| let dayOfWeek = (Sunday:1, Monday:2, Tuesday:3, Wednesday:4, Thursday:5, Friday:6, Saturday:7) | |
This file contains hidden or 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
| // http://stackoverflow.com/questions/24026510/how-do-i-shuffle-an-array-in-swift | |
| extension CollectionType { | |
| /// Return a copy of `self` with its elements shuffled | |
| func shuffle() -> [Generator.Element] { | |
| var list = Array(self) | |
| list.shuffleInPlace() | |
| return list | |
| } | |
| } |
This file contains hidden or 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
| enum Allergies:UInt { | |
| static func hasAllergy(value:UInt, testAgainst: Allergies) -> Bool { | |
| return value & testAgainst.rawValue > 0 | |
| } | |
| case None = 0 | |
| case eggs = 1 | |
| case peanuts = 2 | |
| case shellfish = 4 | |
| case strawberries = 8 |