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 Test: NSObject { // class must extend NSObject | |
override class func load() { | |
println("class loaded!"); | |
} | |
} |
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
array = array.filter( { find(anotherArray, $0) == 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
/// Swift 2 syntax | |
class MyManager: NSObject { | |
static let sharedInstance = MyManager() | |
// Ensure the class cannot be initialized from outside by declaring a private initializer | |
private override init() { | |
super.init() | |
// Do your internal initialization privately | |
} |
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
-- Note when used from Automator: This returns the .app folder when saved as an application but returns the Applications folder when the workflow it's run from Automator. | |
tell application "Finder" | |
set current_path to container of (path to me) as alias | |
end tell |
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
set listOfNames to {} | |
tell application "Finder" | |
set filelist to every file of the desktop | |
repeat with currentFile in filelist | |
set currentFileName to (the name of currentFile) | |
copy currentFileName to the end of listOfNames | |
end repeat | |
end tell | |
choose from list listOfNames |
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
private lazy var debugLabel: UILabel = { | |
let label = UILabel(frame: CGRectMake(20, 20, 200, 20)) | |
label.textColor = UIColor.redColor() | |
label.backgroundColor = UIColor.whiteColor() | |
return label | |
}() // the parentheses tells swift to use the return value of the closure, not the closure itself. |
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 == (lhs: CGPoint, rhs: CGRect) -> Bool { | |
return CGRectContainsPoint(rhs, lhs) | |
} | |
// Example | |
var p1 = CGPoint(x: 10, y: 10) | |
var p2 = CGPoint(x: 10, y: 200) | |
var rect = CGRect(x: 0, y: 0, width: 100, height: 100) | |
if (p1 == rect) { |
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
/// Swift 2 function documentation example | |
/** | |
Documentation with optional Markdown syntax | |
- returns: Bool | |
- parameter param1:String | |
- parameter param2:String | |
- Throws: error lists | |
*/ | |
private func function(param1: String, param2: String) -> Bool { |
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
#define BOUND(VALUE, UPPER, LOWER) MIN(MAX(VALUE, LOWER), UPPER) |
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
@interface ThreadSample () | |
@property (nonatomic, strong) NSThread *thread; | |
@end | |
@implementation ThreadSample | |
#pragma mark - Private |
OlderNewer