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 pb = NSPasteboard.generalPasteboard() | |
func parsePB() { | |
if let data = pb.stringForType("public.utf8-plain-text") { | |
print(data) | |
} | |
if let data = pb.dataForType("public.rtf") { | |
let rtf = try! NSAttributedString(data: data, options: [:], documentAttributes: 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
“Challenge | |
Use two instances of NSDate to figure out how many seconds you have been alive. | |
First, NSDate has an instance method timeIntervalSinceDate:. This method takes one argument – another instance of NSDate. It returns the number of seconds between the NSDate that received the message and the NSDate that was passed in as the argument. | |
It looks something like this: | |
double secondsSinceEarlierDate = [laterDate timeIntervalSinceDate:earlierDate]; | |
Second, you will need to create a new date object that is set to a given year, month, etc. You will do this with the help of an NSDateComponents object and an NSCalendar object. Here is an example: | |
NSDateComponents *comps = [[NSDateComponents alloc] init]; | |
[comps setYear:1969]; | |
[comps setMonth:4]; |
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
NSDateComponents *comps = [[NSDateComponents alloc] init]; | |
[comps setDay:20]; | |
[comps setMonth:01]; | |
[comps setYear:1985]; | |
//[comps setTimeZone:<#(NSTimeZone *)#>]; | |
NSDate *now = [NSDate date]; | |
NSDate *birthday = [NSDate comps]; | |
double difference = [birthday timeIntervalSinceDate:now]; |
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
NSDate *now = [NSDate date]; | |
NSDateFormatter *format = [[NSDateFormatter alloc]init]; | |
[format setDateFormat:@"yyyy-MM-dd"]; | |
NSString *nowDate = [format stringFromDate:now]; | |
NSLog(@"test: %@",nowDate); | |
NSDateComponents *comps = [[NSDateComponents alloc] init]; | |
[comps setDay:27]; | |
[comps setMonth:9]; | |
[comps setYear:1988]; | |
NSCalendar *local = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; |
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 letters = ["0", "a", "b", "c", "d", "e", "f", "g", "h"] | |
let numbers = ["0", "1","2","3","4","5","6","7","8"] | |
func position(column: Int, row: Int) -> String { | |
if (column < letters.startIndex || column > letters.count) { | |
return "The board accepts onlynumbers from 1 to 8" | |
}else if (row < numbers.startIndex || row > numbers.count){ | |
return "The board accepts onlynumbers from 1 to 8" | |
} | |
var pieceAtColumn = letters[column] |
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
I have all these cases that assign a lengthy subview repetitive code: | |
case (1, 1), (1, 8): | |
var value = Piece(color: .w, shape: .R) | |
var pieceImg = NSImage(named: "wR") | |
var pieceView = NSImageView(frame: CGRect(x: squareX, y: squareY, width: cellLength, height: cellLength)) | |
pieceView.image = pieceImg | |
boardView.addSubview(pieceView, positioned: .Above, relativeTo: nil) | |
What if I assign just the: | |
var value = Piece(color: .w, shape: .P) |
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 | |
import Swift | |
enum Shape { | |
case K, Q, B, R, N, P | |
static let allValues = [K, Q, B, R, N, P] | |
} | |
enum Color { | |
case w, 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
enum Shape { | |
case K, Q, B, R, N, P | |
static let allValues = [K, Q, B, R, N, P] | |
} | |
enum Color { | |
case w, b | |
static let allValues = [w, 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
7) a function that lists all the pieces in the configuration of step 6 |
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
CompileSwift normal x86_64 /Users/lfaoro/Development/iLichess Mac/iLichess Mac/Chessboard.swift | |
cd /Users/lfaoro/Development/iLichess Mac | |
/Applications/Xcode-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c "/Users/lfaoro/Development/iLichess Mac/iLichess Mac/AppDelegate.swift" "/Users/lfaoro/Development/iLichess Mac/iLichess Mac/ConnectionManager.swift" -primary-file "/Users/lfaoro/Development/iLichess Mac/iLichess Mac/Chessboard.swift" "/Users/lfaoro/Development/iLichess Mac/iLichess Mac/main.swift" -target x86_64-apple-macosx10.9 -target-cpu core2 -sdk /Applications/Xcode-Beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -I /Users/lfaoro/Library/Developer/Xcode/DerivedData/iLichess_Mac-ddufwfmsgvbzsccxtwxcvovriyqy/Build/Products/Debug -F /Users/lfaoro/Library/Developer/Xcode/DerivedData/iLichess_Mac-ddufwfmsgvbzsccxtwxcvovriyqy/Build/Products/Debug -g -module-cache-path /Users/lfaoro/Library/Developer/Xcode/DerivedData/Mod |
OlderNewer