This file contains hidden or 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
| // Objective-C: | |
| user.userId = @"unknown"; | |
| if ([object isKinfOfClass:[NSDictionary class]]) { | |
| if ([[((NSDictionary *)object) objectForKey:@"user_id"] isKindOfClass:[NSString class]]) { | |
| user.userId = (NSString *)[((NSDictionary *)object) objectForKey:@"user_id"]; | |
| } | |
| } |
This file contains hidden or 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 SSNTextField: UITextField { | |
| required init(coder aDecoder: NSCoder) { | |
| super.init(coder: aDecoder) | |
| registerForNotifications() | |
| } | |
This file contains hidden or 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 MainProcess { | |
| var shouldExit = false | |
| func start () { | |
| // do your stuff here | |
| // set shouldExit to true when you're done | |
| } | |
| } | |
| var runLoop : NSRunLoop |
This file contains hidden or 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 MyArray<Element> : CustomStringConvertible { | |
| var description: String { | |
| var mutableDescription = "[" | |
| for i in 0..<count { | |
| mutableDescription += "\"\(elementAtIndex(i)) " | |
| if i != count - 1 { | |
| mutableDescription += ", " |
This file contains hidden or 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 | |
| class PointerBox<Element> { | |
| var pointer: UnsafeMutablePointer<Element> | |
| let count: Int | |
| init(pointer: UnsafeMutablePointer<Element>, count: Int) { | |
| self.pointer = pointer | |
| self.count = count | |
| } | |
| deinit { |
This file contains hidden or 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
| 2 ==> 0 1 0 | |
| 6 ==> 1 1 0 |
This file contains hidden or 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
| 2 ==> 0 1 0 | |
| 6 ==> 1 1 0 | |
| ---------------- | |
| Different? ✓ ✗ ✗ |
This file contains hidden or 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 calculateHammingDistance(x: Int, y: Int) -> Int { | |
| // Step 1: Find different bits | |
| // Step 2: Count them | |
| } |
This file contains hidden or 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 calculateHammingDistance(x: Int, y: Int) -> Int { | |
| // Step 1: Find different bits | |
| let differentBits = x ^ y | |
| // Step 2: Count them | |
| } |
This file contains hidden or 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
| 2 ==> 0 1 0 | |
| 6 ==> 1 1 0 | |
| ---------------- | |
| 2 ^ 6 ==> 1 0 0 // 100 in binary represents number 4 |
OlderNewer