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 query(domain:String) ->[String] { | |
| var results:[String] = [] | |
| //dispatch_async(q) { [weak self] in | |
| let host = CFHostCreateWithName(nil,domain as CFString).takeRetainedValue() | |
| //NSLog("getIPFromDNS %@", hostName) | |
| //let d = NSDate() | |
| CFHostStartInfoResolution(host, .addresses, nil) | |
| var success: DarwinBoolean = false | |
| if let addresses = CFHostGetAddressing(host, &success)?.takeUnretainedValue() as NSArray? { |
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 | |
| import Dispatch | |
| func test(){ | |
| for _ in 1..<5 { | |
| print("Hello, World!") | |
| } | |
| } | |
| class testclass{ |
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
| //: [Previous](@previous) | |
| import Foundation | |
| var str = "Hello, playground" | |
| import Foundation | |
| // Very slightly adapted from http://stackoverflow.com/a/30141700/106244 | |
| // 99.99% Credit to Martin R! |
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 UIKit | |
| var str = "Hello, playground" | |
| let x = UINT32_MAX | |
| print(Date()) | |
| let q = DispatchQueue.init(label: "test", qos: .background, attributes: .init(rawValue: 0), autoreleaseFrequency: .never, target: nil) | |
| var flag = true | |
| print(q.label) | |
| q.asyncAfter(deadline: .now() + 3) { |
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 Darwin | |
| extension sockaddr_storage { | |
| /// Calls a closure with traditional BSD Sockets address parameters. | |
| /// | |
| /// This is used to call BSD Sockets routines like `connect`, which accept their | |
| /// address as an `sa` and `saLen` pair. For example: | |
| /// | |
| /// let ss: sockaddr_storage = … |
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 Cocoa | |
| var str = "Hello, playground" | |
| let x = UINT32_MAX | |
| class FBQueue { | |
| typealias qblock = ((Void) ->Void) | |
| typealias qfinishBlock = ((Bool) ->Void)? | |
| let call:qblock |
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
| //: Playground - noun: a place where people can play | |
| import Cocoa | |
| var str = "Hello, playground" | |
| import Foundation | |
| import Dispatch | |
| func test(){ |
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
| let persons: [[String: Any]] = [["name": "Carl Saxon", "city": "New York, NY", "age": 44], | |
| ["name": "Travis Downing", "city": "El Segundo, CA", "age": 34], | |
| ["name": "Liz Parker", "city": "San Francisco, CA", "age": 32], | |
| ["name": "John Newden", "city": "New Jersey, NY", "age": 21], | |
| ["name": "Hector Simons", "city": "San Diego, CA", "age": 37], | |
| ["name": "Brian Neo", "age": 27]] //注意这家伙没有 city 键值 | |
| func infoFromState( state: String, persons: [[String: Any]]) | |
| -> Int { | |
| // 先进行 flatMap 后进行 filter 筛选 | |
| // $0["city"] 是一个可选值,对于那些没有 city 属性的项返回 nil |
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 Number /* class cluser */ { | |
| class Int8: Number { | |
| var value: Swift.Int8 | |
| init(_ value: Swift.Int8) { self.value = value } | |
| } | |
| class Int: Number { | |
| var value: Swift.Int | |
| init(_ value: Swift.Int) { self.value = value } | |
| } |