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 string = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi enim lacus, ullamcorper in gravida a, semper id dolor. Mauris quis metus id" | |
extension String { | |
public func split( | |
maxSplit: Int = .max, | |
allowEmptySlices: Bool = false, | |
@noescape isSeparator: ((Character) throws -> Bool)) rethrows -> [String] { | |
return try self.characters.split( | |
maxSplit, |
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
0. Read the <link>FAQ</link>. Other *mandatory* reading follows at the bottom of these rules. | |
1. Google first, ask second. You must work through the Rubber Duck process <i>before</i> asking questions in-channel. | |
2. This is a volunteer-staffed channel. The time of the volunteers is worth at *least* as much as your time. We are not your employees or your servants. Clean your own room, do your own homework, write your own code, and don't forget to say "Thank you" for the help. | |
3. The phrase "doesn't work" isn't allowed. Prepare to explain the problem without links to Stack Overflow. | |
4. Show your code. We don't care about your NDAs. If you don't want to show your code, go pay a consultant. We may ask you to create a minimal project that demonstrates your issue. Save time by doing so before entering the channel. |
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 | |
struct BagGenerator<T:Hashable> : Generator | |
{ | |
typealias Element = (T, Int, Int) | |
var count = 0 | |
var _backingGenerator : DictionaryGenerator<T, Int> | |
init(_ backingDictionary : Dictionary<T, Int>) { | |
_backingGenerator = backingDictionary.generate() | |
} |
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
// | |
// Bag.swift | |
// CmdLineTest | |
// | |
// Created by Erica Sadun on 6/23/14. | |
// Copyright (c) 2014 Erica Sadun. All rights reserved. | |
// | |
import Foundation |
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 Cocoa | |
// See http://www.ruby-doc.org/core-2.1.1/Enumerable.html | |
extension Array { | |
var first : Element? {return self.count > 0 ? self[0] : nil} | |
var last : Element? {return self.count > 0 ? self[self.count - 1] : nil} | |
var random : Element? {return self.count > 0 ? self[Int(arc4random_uniform(UInt32(self.count)))] : nil} | |
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 AbsoluteValuable | |
protocol ArrayBound | |
protocol ArrayBufferType | |
protocol ArrayLiteralConvertible | |
protocol ArrayType | |
protocol BidirectionalIndex | |
protocol BitwiseOperations | |
protocol CVarArg | |
protocol CharacterLiteralConvertible | |
protocol Collection |
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
#! /bin/sh | |
# All credit to @mikeash | |
echo "import Cocoa\n:print_decl $1" | /Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -integrated-repl | open -f |
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 fd = open("/tmp/scratch.txt", O_WRONLY|O_CREAT, 0o666) | |
if fd < 0 { | |
perror("could not open /tmp/scratch.txt") | |
} else { | |
let text = "Hello World\n" | |
write(fd, text, strlen(text)) | |
close(fd) | |
} |
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 fname = "/tmp/scratch.txt" | |
let fptr = fopen(fname, "w") | |
if (fptr == nil) { | |
let localErrno = errno | |
println("Unable to open \(fname): \(strerror(localErrno))") | |
} else { | |
let text = "Hello World\n" | |
let bytesWritten = fwrite(text, UInt(sizeof(Byte)), strlen(text), fptr) | |
println("Wrote \(bytesWritten) bytes") | |
fclose(fptr) |
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 ErrorString1(error : NSError?) -> String { | |
if let theError = error as? NSError { | |
if let description = theError.localizedDescription { | |
return description | |
} | |
} | |
return "" | |
} | |
func ErrorString2(error_ : NSError?) -> String { |
OlderNewer