Python 提供了两个基本的 socket 模块:
Socket
它提供了标准的BSD Socket API。SocketServer
它提供了服务器重心,可以简化网络服务器的开发。
下面讲解下 Socket模块功能。
func dprint(_ objects:Any..., separator: String = " ", terminator: String = "\n",file:String = #file,line:Int = #line, function:String = #function){ | |
#if DEBUG | |
print((file).split(separator: "/").last!,line.description + ":",function) | |
print("🦑 Debug info: \n\t", terminator: "") | |
for i in objects{ | |
print(i, separator: "", terminator: separator) | |
} | |
print(terminator) | |
#endif | |
} |
NSOperationQueue *queue = [[NSOperationQueue alloc] init]; | |
queue.maxConcurrentOperationCount = 1; | |
NSInteger inputValue = 5; | |
NSMutableArray<NSOperation *> *operations = [NSMutableArray<NSOperation *> array]; | |
for (NSInteger i=0; i<inputValue; i++){ | |
NSOperation *operation = [NSBlockOperation blockOperationWithBlock:^{ | |
NSLog(@".Running operation %d", i); | |
[NSThread sleepForTimeInterval:1]; | |
}]; |
#!/usr/bin/env swift | |
import Foundation | |
func oneLoop() -> Double{ | |
var sumValue = 0 | |
let startTime = NSDate().timeIntervalSince1970 | |
for i in 1...100000000 { | |
if (i % 2 == 1) { | |
sumValue++ | |
} else { |
// Release under MIT | |
// Copyright (C) 2015 Xaree Lee | |
#import <Foundation/Foundation.h> | |
/* Get property name for the class (C string or NSSting). */ | |
#define keypathForClass(Klass, PropertyName) \ | |
(((void)(NO && ((void)[Klass _nullObjectForCheckingPropertyName].PropertyName, NO)), # PropertyName)) | |
#define keypathStringForClass(Klass, PropertyName) \ | |
@keypathForClass(Klass, PropertyName) |
// | |
// parkingDate.swift | |
// stopTest | |
// | |
// Created by Laibit on 2015/7/28. | |
// Copyright (c) 2015年 Laibit. All rights reserved. | |
// | |
import UIKit |
#!/bin/sh | |
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal | |
# make sure the output directory exists | |
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}" | |
# Step 1. Build Device and Simulator versions | |
xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build | |
xcodebuild -target "${PROJECT_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build |
override func viewWillDisappear(animated:Bool) { | |
if let currentViewControllers = self.navigationController.viewControllers as? [UIViewController] { | |
if let found = find(currentViewControllers, self) { | |
// Do nothing if the current controller is still in the stack. This means we're going forward, not back | |
} | |
else { | |
self.performSegueWithIdentifier("unwindToLogin", sender:self) | |
} | |
} | |
super.viewWillDisappear(animated) |
var url = NSURL(string: "http://www.stackoverflow.com")
var request = NSURLRequest(URL: url)
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue(), completionHandler: {(response: NSURLResponse!, data: NSData!, error: NSError!) in
println(NSString(data: data, encoding: NSUTF8StringEncoding))