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 Foundation | |
extension String | |
{ | |
// Works in Xcode but not Playgrounds because of a bug with .insert() | |
mutating func insertString(string:String,ind:Int) { | |
var insertIndex = advance(self.startIndex, ind, self.endIndex) | |
for c in string { |
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
extension NSMutableAttributedString { | |
func highlightStrings(stringToHighlight:String, usingRegex:Bool = false) { | |
var useRegex:NSRegularExpressionOptions? | |
if !usingRegex { | |
useRegex = NSRegularExpressionOptions.IgnoreMetacharacters | |
} |
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
// Removed contains() and reduce() from function to make it less expensive | |
func sortedSet<S:CollectionType where S.Generator.Element: Comparable>(seq:S) -> [S.Generator.Element] { | |
var set = sorted(seq){$0<$1} | |
var inds = [Int]() | |
for s in enumerate(set) { | |
if s.index > 0 && s.element == set[advance(set.startIndex, s.index-1,set.endIndex)] { | |
inds.append(s.index-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
protocol XMLDelegateClass { | |
func tagClosed(string:String) | |
func tagOpen (string:String) | |
func stringFound (string:String) | |
} |
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
newStr = "hello 😂😒😡" | |
// the number of elements: | |
let count = newStr.utf16Count | |
// create array of appropriate length: | |
var array = [UInt16](count: count, repeatedValue: 0) | |
for a in enumerate(newStr.utf16) { |
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 SomeClass { | |
class var description:String { | |
return "computed class property" | |
} // ok | |
class var property:String = "class property" // compiler warning: class variables not yet supported | |
class func typeMethod() -> String { | |
return "type method" | |
} // ok |
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 | |
class ViewController: UIViewController { | |
var a:Foo? = Foo() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
var b = a!.myFunc | |
a = nil | |
println(b()) |
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
// This code accompanies the following post: http://sketchytech.blogspot.co.uk/2014/11/swift-translating-and-rotating.html | |
import UIKit | |
class ViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view, typically from a nib. | |
let newView = View(frame: CGRect(x: 0, y: 0, width: CGRectGetWidth(self.view.frame), height: CGRectGetHeight(self.view.frame))) |
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 | |
class ViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view, typically from a nib. | |
var blueLayer = CALayer() |
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
// accompanies this blogpost http://sketchytech.blogspot.co.uk/2014/11/swift-how-to-draw-clock-face-using.html | |
import UIKit | |
class ViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view, typically from a nib. |
OlderNewer