Skip to content

Instantly share code, notes, and snippets.

public class func askDevice() -> NSData?{
// devicePacket packet = {PACKET_HEADER_HEAD,0,PACKET_HEADER_DEVICE_ID_UNKNOWN,COMMAND_ASK_DEVICE,0};
//
// size_t headerSize = sizeof(packet.deviceHeader);
// size_t contentSize = 0;
// size_t size = headerSize + contentSize;
// packet.deviceHeader.len = contentSize;
//
// packet.deviceHeader.checksum = [self checksumWithBytes:(Byte *)&packet.deviceHeader WithSize:(int)size];
@yume190
yume190 / T12345.swift
Last active August 29, 2015 14:04
test1234
class packetFactory{
class func sender<T where T:Constructible, T:Packable>(command:devicePacketHeader.commandType,content:T) -> devicePacketSender<T>?{
var header:devicePacketHeader
switch (command,content){
case (.ASK_DEVICE,let TAsk) where TAsk is devicePacketNil:
header = devicePacketHeader(deviceID: .UNKNOWN, command: command, len:Int16(sizeof(T)))
// case (_,let TNil) where TNil is devicePacketNil:
// fallthrough
@yume190
yume190 / StructTest.swift
Last active August 29, 2015 14:04
Swift Struct to NSData
protocol Constructible {
init()
}
struct devicePacketHeader{
var head:Byte = 1;
var checksum:Byte = 2;
var deviceID:Byte = 3;
var command:Byte = 4;
var len:Int16 = 5;
@yume190
yume190 / XARC.h
Created July 7, 2014 07:04
Who retain my text??
@interface XARC : NSObject
@property(nonatomic,strong) NSString* text;
@end
@implementation XARC
//-(NSString *)text{
// return _text;
//}
@end
@yume190
yume190 / UsefulMacro.h
Last active August 29, 2015 14:03
Objetive-C useful Macro
//source : http://blog.csdn.net/yiya1989/article/details/7849588
#define myprintf(...) printk("[lch]:File:%s, Line:%d, Function:%s," \
__VA_ARGS__, __FILE__, __LINE__ ,__FUNCTION__);
//source : http://stackoverflow.com/questions/969130/how-to-print-out-the-method-name-and-line-number-and-conditionally-disable-nslog
#ifdef DEBUG
# define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
#else
# define DLog(...)
#endif
//
// VerticallyAlignedLabel.m
//
#import "VerticallyAlignedLabel.h"
@implementation VerticallyAlignedLabel
@synthesize verticalAlignment = verticalAlignment_;
//
// VerticallyAlignedLabel.h
//
#import <Foundation/Foundation.h>
typedef enum VerticalAlignment {
VerticalAlignmentTop,
VerticalAlignmentMiddle,
// Label2.mm
// (c) 2009 Ivan Misuno, www.cuberoom.biz
#import "Label2.h"
@implementation Label2
-(id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
// Label2.h
// (c) 2009 Ivan Misuno, www.cuberoom.biz
#import <UIKit/UIKit.h>
typedef enum
{
VerticalAlignmentTop = 0, // default
VerticalAlignmentMiddle,
VerticalAlignmentBottom,
@yume190
yume190 / alertController.m
Last active August 29, 2015 14:02
UIAertController Usage
changeAlert = [UIAlertController alertControllerWithTitle:@"title" message:@"message" preferredStyle:UIAlertControllerStyleAlert];
UIAlertController* __weak weakAlert = changeAlert;
UIAlertAction *alertActionOk = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
UITextField *t = [[weakAlert textFields] firstObject];
DLog(@"%@",t.text);
[weakAlert dismissViewControllerAnimated:YES completion:nil];
}];
UIAlertAction *alertActionCancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
DLog(@"%@",action);