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
var range = baseString.rangeOfString("Hello") | |
// wrap in while loop with .containsString() | |
var ranges : [NSRange] = [] | |
while baseString.containsString("Hello") { | |
let nsRange = baseString.rangeOfString("Hello") | |
ranges.append(nsRange) | |
} |
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
var string = "Hello, playground" | |
var baseString = NSMutableString(string: string) | |
if baseString.containsString("Hello") { | |
// do things when "Hello" is found | |
} |
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
while baseString.containsString("Hello") { | |
let nsRange = baseString.rangeOfString("Hello") | |
ranges.append(nsRange) | |
var replaceString = "" | |
for _ in 0..<nsRange.length { | |
replaceString += "§" // secret unallowed character | |
} | |
baseString.replaceCharactersInRange(nsRange, withString: replaceString) | |
} |
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
let highlightedString = NSMutableAttributedString(string: string) | |
for i in 0..<ranges.count { | |
highlightedString.addAttribute(NSForegroundColorAttributeName, value: UIColor.redColor(), range: ranges[i]) | |
} |
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
class SyntaxGroup { | |
var wordCollection : [String] // it will search for these words | |
var type : String // purely a reference | |
var color : UIColor // the words will get this color | |
init(wordCollection_I : [String], type_I : String, color_I: UIColor) { | |
wordCollection = wordCollection_I | |
type = type_I | |
color = color_I | |
} |
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
let ticket = ticketMan.ticket | |
//put this inside a loop | |
if self.ticketMan.validateTicket(ticket) == false { | |
self.ticketMan.ripTicket(ticket) // destroy ticket | |
return // escape from function | |
} | |
//this is the end of the highlighting function | |
dispatch_sync(dispatch_get_main_queue()) { () -> Void in |
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
func highLight(string : String, completion: (finished: Bool) -> Void) { | |
let qualityOfServiceClass = QOS_CLASS_DEFAULT | |
let backgroundQueue = dispatch_get_global_queue(qualityOfServiceClass, 0) | |
dispatch_async(backgroundQueue) { () -> Void in | |
// actual syntax highlighting here | |
dispatch_sync(dispatch_get_main_queue()) { () -> Void in |
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
class TicketMan { | |
private var ticketStack : Int = 0 | |
private var ticketCounter : Int = 0 | |
var ticket : Int { | |
get { | |
ticketStack += 1 | |
ticketCounter += 1 | |
return ticketCounter |
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 toggleSwitch = UISwitch() | |
var realFrame : CGRect? | |
let frame = toggleSwitch.frame | |
let bounds = toggleSwitch.bounds | |
let subViews = toggleSwitch.subviews |
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 | |
extension SubviewsCGRectUnion { | |
mutating func setCGRectUnionWithSubviews() { | |
frame = getCGRectUnionWithNestedSubviews(subviews: subviews, frame: frame) | |
fixPositionOfSubviews(subviews, frame: frame) | |
} | |
func getCGRectUnionWithSubviews() -> CGRect { | |
return getCGRectUnionWithNestedSubviews(subviews: subviews, frame: frame) |
OlderNewer