class CRC32 {
var data = NSData()private static let crcTableLength = Int(UInt8.max) + 1private static var _crcTable = [UInt32](count: crcTableLength, repeatedValue: 0)private static var crcTable: [UInt32] {get {if _crcTable[1] != 0 {return _crcTable}for n in 0..var c = UInt32(n)for _ in 0..<8 {if ((c & 1) != 0) {c = 0xedb88320 ^ (c >> 1)} else {c = c >> 1}}_crcTable[n] = c}return _crcTable}}func getCRC() -> Byte4 {var crc: Byte4 = 0crc = ~crcvar buf = UnsafePointer<UInt8>(data.bytes)let len = data.lengthfor _ in 0..let toBuf = buf.memorybuf += 1let i = Int((crc ^ UInt32(toBuf)) & 0xFF)crc = self.dynamicType.crcTable[i] ^ crc >> 8}return ~crc}}
2016年8月18日 星期四
swift + crc32
2016年8月9日 星期二
HTML+UILabel(or TextView)
On swift
var attrStr = try! NSAttributedString(
data: "text".dataUsingEncoding(NSUnicodeStringEncoding, allowLossyConversion: true)!,
options: [ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType],
documentAttributes: nil)
label.attributedText = attrStr
On java
myTextView.setText(Html.fromHtml("
Description here
"));
Title
Description here
"));
訂閱:
文章 (Atom)