天使的白骨

给我一个EMACS,我不需要操作系统
 
 

常用链接

  • 我的随笔
  • 我的评论
  • 我参与的随笔

留言簿(16)

  • 给我留言
  • 查看公开留言
  • 查看私人留言

随笔分类(49)

  • C++ lisp perl ruby python(15) (rss)
  • EMACS,飞(1) (rss)
  • linux(6) (rss)
  • QNX(2) (rss)
  • server(2) (rss)
  • 技术简历 (rss)
  • 开源项目(8) (rss)
  • 量子计算机(1) (rss)
  • 设计模式(14) (rss)

随笔档案(61)

  • 2018年12月 (1)
  • 2017年7月 (1)
  • 2017年4月 (1)
  • 2017年3月 (1)
  • 2017年1月 (1)
  • 2016年7月 (2)
  • 2016年3月 (1)
  • 2015年10月 (1)
  • 2015年6月 (1)
  • 2015年4月 (2)
  • 2015年1月 (2)
  • 2014年11月 (1)
  • 2014年10月 (2)
  • 2014年9月 (1)
  • 2014年8月 (2)
  • 2014年7月 (1)
  • 2014年6月 (4)
  • 2014年5月 (1)
  • 2014年4月 (1)
  • 2014年1月 (9)
  • 2013年12月 (8)
  • 2013年10月 (2)
  • 2013年9月 (1)
  • 2013年7月 (1)
  • 2013年5月 (1)
  • 2013年4月 (1)
  • 2013年3月 (1)
  • 2012年9月 (1)
  • 2012年3月 (2)
  • 2012年2月 (2)
  • 2011年11月 (1)
  • 2011年9月 (2)
  • 2011年7月 (1)
  • 2010年5月 (1)

文章分类(18)

  • algorithm and structure(2) (rss)
  • Linux(13) (rss)
  • 软件工程与架构(1) (rss)
  • 正则表达式(2) (rss)

文章档案(34)

  • 2018年12月 (1)
  • 2016年9月 (1)
  • 2015年1月 (1)
  • 2014年7月 (1)
  • 2014年6月 (1)
  • 2014年5月 (1)
  • 2013年9月 (2)
  • 2013年6月 (1)
  • 2013年4月 (3)
  • 2013年3月 (2)
  • 2012年12月 (2)
  • 2012年10月 (2)
  • 2012年9月 (1)
  • 2012年8月 (2)
  • 2012年3月 (2)
  • 2012年1月 (1)
  • 2011年11月 (1)
  • 2011年9月 (1)
  • 2011年7月 (1)
  • 2011年6月 (3)
  • 2011年4月 (1)
  • 2010年11月 (2)
  • 2010年9月 (1)

嵌入式

  • 媒体播放器的三大底层架构
  • 101条计算机经典语录
  • ajax教程
  • ajax向服务器发送请求
  • Biologically Motivated Programming Technology for Robust Systems
  • Chrome的进程间通信
  • chrome多进程架构
  • emacs cscope配置
  • emacser cedet
  • GStreamer 简化 Linux 多媒体开发
  • gstreamer插件开发指南
  • iptable配置
  • pyQt
  • pyQt examples
  • python官方学习手册
  • slime--common lisp与emacs的集成开发
  • stackoverflow
  • UNIX技术网
  • VI使用手册
  • vlc hacker guide
  • vlc播放器官方地址
  • 非常优秀的书:开源软件的架构
  • 开源中国
  • 嵌入式的一些关键点,这个作者的文章不错
  • 清除svn保存的username用户名和paasword密码(windows和linux)
  • 使用emacs开发iPhone应用程序
  • 心理学

软件工程

  • 项目延时的主要原因
  • 描述了项目延时的几个重大可能因素

算法

  • MapReduce----google核心并行图算法

搜索

  •  

最新评论

  • 1. re: UINavigationController的使用,隐藏,定制
  • 不错
  • --臂化羽
  • 2. re: 谈谈MVVM和MVC,使用swift集成RFP框架(ReactiveCocoa)
  • 嗯,我后来就没怎么用。rac。现在开始用了。把作者写的那个struct直接拷贝过来了。再一次为作者点赞!
  • --言十年
  • 3. re: 谈谈MVVM和MVC,使用swift集成RFP框架(ReactiveCocoa)[未登录]
  • @laznrbfe
    @猴子
    @言十年
    我已经更过github上的代码了
  • --何清龙
  • 4. re: 谈谈MVVM和MVC,使用swift集成RFP框架(ReactiveCocoa)
  • Swift2.0的分享失效了。
    我的QQ:912692610.
    希望得到你的帮助。
  • --laznrbfe
  • 5. re: 谈谈MVVM和MVC,使用swift集成RFP框架(ReactiveCocoa)
  • @言十年
    希望得到2.0的代码进行学习.十分感谢.214449165@qq.com
  • --猴子
  • 6. re: 谈谈MVVM和MVC,使用swift集成RFP框架(ReactiveCocoa)
  • 评论内容较长,点击标题查看
  • --言十年
  • 7. re: json自动生成代码(object-c、java、 C#、C++)[未登录]
  • 大叔大婶
  • --111
  • 8. re: UINavigationController的使用,隐藏,定制[未登录]
  • @Keater
    我没有两者一起用过,我们的滑动返回由其他人做成全局的了,统一在UINavigationController的子类中处理
  • --何清龙
  • 9. re: UINavigationController的使用,隐藏,定制
  • 评论内容较长,点击标题查看
  • --Keater
  • 10. re: EMACS配置(.emacs)
  • 评论内容较长,点击标题查看
  • --何清龙
  • 11. re: EMACS配置(.emacs)
  • @马前进
    可以交流,我试过,但是有点忘了
  • --何清龙
  • 12. re: EMACS配置(.emacs)
  • 我想使用emacs进入交叉调试,能指导下吗。使用的gdb是针对arm平台的。
  • --马前进
  • 13. re: 不分配动态内存翻转单向链表
  • @落单的毛毛虫
    你的代码更简洁,原理还是一样的
  • --何清龙
  • 14. re: 不分配动态内存翻转单向链表
  • 评论内容较长,点击标题查看
  • --落单的毛毛虫
  • 15. re: 不分配动态内存翻转单向链表[未登录]
  • 冒泡排序的思想?
  • --kk
  • 16. re: 苹果新语言swift的通盘整理
  • @mybios
    比object-c好一点,说实话,可读性不行,写起来倒是挺快的,他有函数编程能力,这点不错,其他的可有可无,模板做得烂。
  • --何清龙
  • 17. re: 苹果新语言swift的通盘整理[未登录]
  • 又一个苹果出的新版反人类语言。
  • --mybios
  • 18. re: 苹果新语言swift的通盘整理
  • thx`
  • --java论坛
  • 19. re: 苹果新语言swift的通盘整理
  • @java论坛
    这个语言刚出来几天
  • --何清龙
  • 20. re: 苹果新语言swift的通盘整理
  • swift?
    你写的是什么语言,我怎么看不懂

    http://www.itqx.net
  • --java论坛

评论排行榜

  • 1. 年底了,说说我退出创业后的感想(12)
  • 2. chrome代码里面发现的好东西,很有意思。想了好久,目前也只有这个解释了--为了更安全(11)
  • 3. 近期计划(8)
  • 4. 苹果新语言swift的通盘整理(7)
  • 5. QT相框,发布点代码,有兴趣的随便研究(7)

Powered by: 博客园
模板提供:沪江博客
C++博客 | 首页 | 发新随笔 | 发新文章 | 联系 | | 管理

swift 编码规范
@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css); @import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
/*swift编码规范:
转载轻注明出处
参考资料:《Github 官方分享的Swift 编码规范》
格式化代码:
1.大括号
统一使用缩进,除非特殊阅读需求,比如bolck中有时候多层嵌套,为了方便阅读,可以适当使用换行的括号

2. 空格 VS tabs
只允许使用空格,将编辑器设置为1个TAB = 4个字符缩进

3. 每行的长度
▪ 每行最多不得超过100个字符,80字符的标准有点少,这导致过于频繁的换行
以15寸Macbook Pro的大小,每行100个字符时能最大化地同时容下编辑器和iPhone模拟器
通过 “Xcode => Preferences => TextEditing => 勾选Show Page Guide / 输入
100 => OK” 来设置提醒

4.方法的声明和定义
函数参数体和返回值类型之间留一个空格,例如
*/
func add1(x: Int, y: Int) -> Int{
    return x+y
}
func add2(x: Int) -> (Int->Int) {
    return {y in return x + y}
}
func add3(x: Int)(y: Int) -> Int{
    return x+y
}

let resultAdd1 = add1(1, 2)
let resultAdd2 = add2(1)(2)
let resultAdd3 = add3(1)(y:2)
/*
这样使得阅读的时候能最大程度的区分入参和回参
参数定义的逗号分隔符后至少留一个空格,参数过长超过100列的时候,酌情使用换行。

5.◦ 方法的调用
 调用方法沿用声明方法的习惯。例外:如果给定源文件已经遵从某种习惯,继续遵从那种习惯。
 所有参数应在同一行中,如果超出屏幕,多出的参数进行换行。

6.◦ 类名
 类名的首字母大写,写使用首字母大写的形式
分割单词
 在面向特定应用的代码中,类名应尽量避免使用前缀,每个类都使用相同的前缀影响可读性。
 在面向多应用的代码中,推荐使用前缀。如:GTMSendMessage

7.方法名
 方法名的首字母小写,且使用首字母大写的形式分割单词。方法的参数使用相同的规则。
 方法名+参数应尽量读起来像一句话

8.变量名
 变量名应使用容易意会的应用全称,且首字母小写,且使用首字母大写的形式分割单词
 在类中使用类成员变量时,除非是在block中或者为了区分参数或者临时变量,才特别标明self.xxx
需要时才写上 self, 当调用self的 properties 或 methods 时,self用默认的隐式引用:
例如:
*/


class Event{}
private class History {
    var events: [Event] = []

    func rewrite() {
        events = []
    }
}
//必要的时候再加上self, 比如在闭包里,或者 参数名冲突了:

extension History {
    convenience init(events: [Event]) {
        self.init()
        self.events = events
    }

    var whenVictorious: () -> () {
        return {
            self.rewrite()
        }
    }
}

/*
原因: 在闭包里用self更加凸显它的语义,并且避免了别处的冗长
9.相对于 classes 先选 structs

除非你需要 class 才能提供的功能(比如identity或 deinitializers),不然就用 struct

10.当指定一个类型时,把 冒号和标识符 连在一起
当指定标示符的类型时,冒号要紧跟着标示符,然后空一格再写类型
*/
class SmallBatchSustainableFairtrade: NSObject {  }

let timeToCoffee: NSTimeInterval = 2
enum CoffeeType{}
func makeCoffee(type: CoffeeType) -> NSObject { return NSObject() }

/*
11.能不写类型参数的就别写了
12.变量定义即初始化,使用lazy变量定义延迟的初始化,而不是使用函数。
13.对于只有get特性的变量,为了使代码最简化且可读性强,直接这样:
*/
var readOnly:Int{
    return 0
}
/*
14.让所有可引用对象变量只存在一个强引用,其他地方都使用weak,除非特别需要。
15. if语句中,省略默认的左右括号,可读性更强,修改更方便。多个判断的时候也只用括号包含需要约束的并列条件或递推条件
比如:
if a == 5 {
}else{
}

if (b == 7 && c == 8) || d == 9{
}

16.所有block的定义中,对于self的引用都需要设置弱引用。
例如
x.map{[weak self] $0*2}
*/
posted @ 2015-04-22 12:02 何清龙 阅读(931) | 评论 (0) | 编辑 收藏
 
swift技巧个人总结
1.跨语言(object-c,C++,C)全局变量和函数
在object-c层面声明为extern的; 然后在对应的头文件中定义实际内容。例子:
//ConstVarible.h中的内容
#pragma mark - 默认的app更新下载地址
extern const int itunesId;
extern const NSString *kNornalAppAddress;
extern const NSString *kBaseURL;
//函数也是一样的,


//ConstVarible.m或者.c .cpp中的内容
const int itunesId = 923818540;
const NSString *kNornalAppAddress = @"https://itunes.apple.com/us/app/xian-ren-zhang-gu-piao/id923818540?l=zh&ls=1&mt=8";
然后在对应的跨语言头文件中import该头文件,项目的pch文件中import头文件,即两种语言使用同一个实体全局变量。

2.类和函数的静态变量:
由于没有提供class中直接static变量的办法,所以转用内部定义一个结构体,然后结构体中定义static变量,我的习惯是:
struct STATIC{
            static var headerHeight:CGFloat = 0
        }
        if STATIC.headerHeight == 0{
            STATIC.headerHeight = self.tableView(timeTable, heightForHeaderInSection: indexPath.section)
        }
3.MVVM或者MVC中的变量使用:
你可能想过这种办法:
extension UIView{
    var originX:CGFloat{
        get{ return self.frame.origin.x }
        set{
            var tmpFrame = self.frame
            tmpFrame.origin.x = newValue
            self.frame = tmpFrame
        }
    }

但是我保证你还没有想到这个办法:
class HotThemesVC: BaseLoadingEmptyVC {
    var data:Array<MotifsEntity>!{
        get{
            return tableDD.data
        }
        set{
            tableDD.data = newValue
        }
    }
}
这样做,在当前类中使用的data就变成了对应的tableDD中得data,不再受语法干扰,类似python中得import ...效果。

4.typealias 可传递类型定义:

class TopicTableVC:UIViewController{
    typealias RowDataType     = ThemesTableVC.RowDataType
    typealias TableData       = ThemesTableVC.TableData
    typealias CellType        = ThemesTableVC.CellType
}

class ThemesTableVC{
    typealias RowDataType     = PortfoliosEntity
    typealias TableData       = Array<RowDataType>
    typealias CellType        = CombinationCell
}
这一招我是从C++的STL中得traits技术上学来的
5.tuple的使用,swift新增了元组类型,python的招式。可以直接传递元组作为参数,这在传递多个对象但是由不愿意从新去定义一个结构体(含有这些参数作为成员)时,非常有用。。当然了,也可以直接返回元组,甚至是函数或者闭包的元组。例如我在计算日期的时候,就经常这样:
let (year, month, day) = caculate("20140130")

6.Optional的使用,一个变量声明为:
var x:Int? = nil
其本质为 Optional<Int> *x, Optional是一个模板,要么返回对象本身(使用?或者!进行解包的时候),要么返回none告知if语句这个东西是空的。
所以使用习惯是:
if let a = x {
//x指向实际内容,而不是空指针。这在很多时候用得着,比如一个UIView要使用导航控制器,但是有时候也有可能是nil的时候。
}

7.延迟初始化:在首次使用的时候才初始化,如果变量依赖于对象的某些特性,这个很有用,我经常这样创建一些view,这样节省性能。
class A:NSObject{

lazy var topView: ThemesTopView! = { return ThemesTopView.instance() }()

}

8.判断对象的类型:不再使用isKindOfClass。
    func pushToDetail<T>(result:T){
        isPopedFromNav = true

        var vc:UIViewController! = nil
        if result is SStockDataEntity{
            let model = result as SStockDataEntity
            let stockModel = XRZStockModel()
            (stockModel.name, stockModel.code) = (model.name, model.code)
            vc = XRZStockMarketViewController(stockMarkStyle: StockMarketStyle.OneStockMarketStyle, withStocks: [stockModel], withPage: 0);
        }else if result is SPortfoliosDataEntity {
            let model = result as SPortfoliosDataEntity
            MobClick.event("search_result")
            vc = XRZGroupDetailsViewController();
            (vc as XRZGroupDetailsViewController).groupId = "\(model.id)"
            (vc as XRZGroupDetailsViewController).setTitle(model.name, andColorIndex:0)
        }else{
            let model = result as SUserDataEntity
            vc = XRZFinancialViewController(nibName: "XRZFinancialViewController", bundle: nil)
        }

        self.vm?.navigationController?.pushViewController(vc, animated: true)
    }


posted @ 2015-04-03 18:14 何清龙 阅读(1448) | 评论 (0) | 编辑 收藏
 
How to find a range of a String in another String in swift
I tried to use NSMutableAttributedString to show a reach text in UILabel, but I've found it's hard to got a method to find out the range of the-string inside of a string. Here is what that I've done.hope this helped you!
let attrString = NSMutableAttributedString(string:desc)
        if let strRange =  desc.rangeOfString(stringInSearchBar){
            let distanceBegin = distance(desc.startIndex, strRange.startIndex)
            let distanceEnd = distance(desc.startIndex, strRange.endIndex)
            let range = NSMakeRange(distanceBegin, distanceEnd - distanceBegin)
            attrString.addAttribute(NSForegroundColorAttributeName, value: UIColor.markColorRed(), range:range)
        }
posted @ 2015-01-14 12:01 何清龙 阅读(2064) | 评论 (0) | 编辑 收藏
 
solve crosse language of object-c & swift UIScrollViewDelegate/UITableViewDelegate rac_signalForSelector("scrollViewDidEndDragging:willDecelerate:") crash
Chinese readers annotation:这个问题google,stackoverflow,github都还没有相关资料,所以把内容写成英文的,以便于帮助国外的朋友。
English readers annotation:This problem has not been found by google or stackoverflow or github yet. So I writed it at here so that you could get help from this.(By the way, I am a Chinese)

I want to use rac_signalForSelector to observe the UITableView's delegate so I could let the dataDelegate and delegate being reused from a independent class. So If they have the same cell, I would not need to implement them triples.

If you use the RAC(which means ReactiveCocoa), Firstly come into you head is a code sample like this:
self.rac_signalForSelector(Selector("scrollViewDidEndDecelerating:")).subscribeNext{ _ in
            self.setTabBarVisiable(false, animated:true)
        }
scrollView.delegate = self

well...It's fine if you don't need this method:
self.rac_signalForSelector("scrollViewDidEndDragging:willDecelerate:").subscribeNext{ _ in
            self.setTabBarVisiable(false, animated:true)
        }
But if you do, you will get a crash message(EXE_BAD_ACCESS) which caused by the RAC.It means RAC can't find a method form string '@' (which should be @"scrollViewDidEndDragging:willDecelerate:
"),  So I have work around with it,  and I guessed it's the reason of swift Protocol isn't a NSObject(you could see from UIScrollViewDelegate's declaration). 

By a chance I found there is a method named 'NSProtocolFromString' and RAC provided a method 
- (RACSignal *)rac_signalForSelector:(SEL)selector fromProtocol:(Protocol *)protocol;


So I combined them both
self.rac_signalForSelector("scrollViewDidEndDragging:willDecelerate:",
            fromProtocol:NSProtocolFromString("UITableViewDelegate")).subscribeNext{ _ in
            self.setTabBarVisiable(false, animated:true)
        }

It doesn't crash any more and the function of my design worked fine. So, that's the way! done!
Hope this helps you out, it's really struggle.
posted @ 2015-01-08 10:34 何清龙 阅读(2902) | 评论 (0) | 编辑 收藏
 
ios笔记,随记。
@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);

Unknown class in Interface Builder file

Check your nibs or storyboard, and make sure none of your views are set to the class!

swift中的注释说明:
TODO: + 说明:
如果代码中有该标识,说明在标识处有功能代码待编写,待实现的功能在说明中会简略说明。比如  //TODO:加入登陆功能.

FIXME: + 说明:
如果代码中有该标识,说明标识处代码需要修正,甚至代码是错误的,不能工作,需要修复,如何修正会在说明中简略说明。

XXX: + 说明:
如果代码中有该标识,说明标识处代码虽然实现了功能,但是实现的方法有待商榷,希望将来能改进,要改进的地方会在说明中简略说明。

关于UIView的autoresizingMask属性的研究

在 UIView 中有一个autoresizingMask的属性,它对应的是一个枚举的值(如下),属性的意思就是自动调整子控件与父控件中间的位置,宽高。

1
2
3
4
5
6
7
8
9
enum {
   UIViewAutoresizingNone                 = 0,
   UIViewAutoresizingFlexibleLeftMargin   = 1 << 0,
   UIViewAutoresizingFlexibleWidth        = 1 << 1,
   UIViewAutoresizingFlexibleRightMargin  = 1 << 2,
   UIViewAutoresizingFlexibleTopMargin    = 1 << 3,
   UIViewAutoresizingFlexibleHeight       = 1 << 4,
   UIViewAutoresizingFlexibleBottomMargin = 1 << 5
};

 

UIViewAutoresizingNone就是不自动调整。
UIViewAutoresizingFlexibleLeftMargin 自动调整与superView左边的距离,保证与superView右边的距离不变。
UIViewAutoresizingFlexibleRightMargin 自动调整与superView的右边距离,保证与superView左边的距离不变。
UIViewAutoresizingFlexibleTopMargin 自动调整与superView顶部的距离,保证与superView底部的距离不变。
UIViewAutoresizingFlexibleBottomMargin 自动调整与superView底部的距离,也就是说,与superView顶部的距离不变。
UIViewAutoresizingFlexibleWidth 自动调整自己的宽度,保证与superView左边和右边的距离不变。
UIViewAutoresizingFlexibleHeight 自动调整自己的高度,保证与superView顶部和底部的距离不变。
UIViewAutoresizingFlexibleLeftMargin  |UIViewAutoresizingFlexibleRightMargin 自动调整与superView左边的距离,保证与左边的距离和右边的距离和原来距左边和右边的距离的比例不变。比如原来距离为20,30,调整后的距离应为68,102,即68/20=102/30。

其它的组合类似。


解决Xcode中swift语言查找符号Symbol not found的问题。更换工程的SDK为7.1或者其他版本,应该是SDK8.0的bug

swift使用数组+=错误:Array<AnyObject>! is not identical to 'UInt8'
The += operator on arrays only concatenates arrays, it does not append an element. This resolves ambiguity working with Any, AnyObject and related types.
UIView不支持深拷贝,先压缩之后在解压,通过获取解压的版本来得到新的副本
UIView *newView = [NSKeyedUnarchiver unarchiveObjectWithData:[NSKeyedArchiver archivedDataWithRootObject:oldView]];

UITableView设置grounped特性之后,顶部空白了一段区域,解决办法:
       tableView.sectionHeaderHeight = 0
        tableView.sectionFooterHeight 
= 0
        tableView.rowHeight           
= 0
object-c 将NSString转换为json 字典.
NSString *data;  //一个json格式的字符串
NSDictionary *json =
    [NSJSONSerialization JSONObjectWithData: [data dataUsingEncoding:NSUTF8StringEncoding]
                                options: NSJSONReadingMutableContainers
                                  error: 
&error];

posted @ 2014-11-12 13:30 何清龙 阅读(1553) | 评论 (0) | 编辑 收藏
 
AFNetworking cache的BUG来了(AFNetworking 304 turned to 200 code)
根据HTTP的协议规定,304表示缓存,200表示成功,其他表示失败。AFNetworking默认是把304的Code变成200了,然后去拿缓存数据。这个在我们需要自定义304策略的时候会有问题。解决方案是为AFHTTPSessionManager的requestSerializer设置标准行为.

 [httpSessionManager.requestSerializer setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];


附一份自己的代码,免得下次进来忘记了。

+(NSURLSessionDataTask *)productGET:(NSString *)interfacePath
                          tableType:(NSString *)page
                            success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
                            failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure
{
    [EasyNetwork userIdSuccess:^(NSString *userId) {
        AFHTTPSessionManager *httpSessionManager =[AFHTTPSessionManager manager];
        httpSessionManager.responseSerializer = [AFJSONResponseSerializer serializer];
        [httpSessionManager.requestSerializer setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
        NSString *key = [NSString stringWithFormat:@"%@-%@", @"If-Modified-Since", page];
        NSString *date = [[LocalCache sharedCache] cachedObjectForKey:key];
        
        if(date != nil && ![date isEqualToString:@""]){
            [httpSessionManager.requestSerializer setValue:@"Wed, 23 Oct 2014 05:13:30 GMT"  //date
                                        forHTTPHeaderField:@"If-Modified-Since"];
        }
        
        NSString *path = [NSString stringWithFormat:@"%@%@&userId=%@", kBaseURL, interfacePath, userId];
        path =  [path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        [httpSessionManager GET:path
                     parameters:nil
                        success:^(NSURLSessionDataTask *task, id responseObject){
                            NSString *tmp = [httpSessionManager.requestSerializer valueForHTTPHeaderField:@"If-Modified-Since"];
                            NSLog(@"Request  If-Modified-Since:%@", tmp);
                            if ([task.response isKindOfClass:[NSHTTPURLResponse class]]) {
                                NSHTTPURLResponse *r = (NSHTTPURLResponse *)task.response;
                                NSLog(@"StatusCode:%d" ,[r statusCode]);
                                NSDictionary *header = [r allHeaderFields];
                                NSString *date = [header objectForKey:@"Last-Modified"];
                                [[LocalCache sharedCache] storeCacheObject:date
                                                                    forKey:key];
                            }
                            success(task, responseObject);
                        }
                        failure:^(NSURLSessionDataTask *task, NSError *error) {
                            if ([task.response isKindOfClass:[NSHTTPURLResponse class]]) {
                                NSHTTPURLResponse *r = (NSHTTPURLResponse *)task.response;
                                NSLog(@"StatusCode:%d" ,[r statusCode]);
                                NSDictionary *header = [r allHeaderFields];
                                NSString *date = [header objectForKey:@"Last-Modified"];
                                [[LocalCache sharedCache] storeCacheObject:date
                                                                    forKey:key];
                            }
                            
                            failure(task, error);
                        }
         ];
    } userIdFailure:^{
        failure(nil, nil);
    }];
    return nil;
}
posted @ 2014-10-22 14:54 何清龙 阅读(4602) | 评论 (0) | 编辑 收藏
 
解决iosUItableView的cell覆盖按钮内容的方案
在ios中编辑UITableView的时候,删除按钮会被表格元素遮挡,查了一下stackoverflow和Google,加上发展具有中国特色社会主义的代码方案,在UITableViewCell中加入:

- (void)layoutSubviews

{

    [super layoutSubviews];

    for (UIView *subview in self.subviews) {

        for (UIView *subview2 in subview.subviews) {

            if ([NSStringFromClass([subview2 class]) isEqualToString:@"UITableViewCellDeleteConfirmationView"]) {

                // move delete confirmation view

                [subview bringSubviewToFront:subview2];

            }

        }

    }

}

总算可以显示了,目前也只能显示全“删除”两个字,再调整位置就会影响体验了。还是中国特色社会主义路线好啊
posted @ 2014-10-09 15:51 何清龙 阅读(2829) | 评论 (0) | 编辑 收藏
 
UIPageViewController第一页不能自动适应子View的Frame的问题。
这个问题困扰了我两天,以为无解了,看了一天的英文资料,最后发现这是apple的BUG!shit
解决方案是这样:连续调用setViewController两次。
__weak UIPageViewController* pvcw = pvc;
[pvc setViewControllers:@[page]
    direction:UIPageViewControllerNavigationDirectionForward
    animated:YES completion:^(BOOL finished) {
        UIPageViewController* pvcs = pvcw;
        if (!pvcs) return;
        dispatch_async(dispatch_get_main_queue(), ^{
            [pvcs setViewControllers:@[page]
                direction:UIPageViewControllerNavigationDirectionForward
                animated:NO completion:nil];
        });
    }];
对于苹果的这种BUG,我只能表示蛋疼!如果你要学习UIPageViewController,在xcode中新建一个page Based工程就是了。
参考资料:iOSBook-chpter19
posted @ 2014-09-26 14:45 何清龙 阅读(2962) | 评论 (0) | 编辑 收藏
 
令人蛋疼的 iOS7.0 中的autolayout问题
今天花了一下午的时间解决iOS的适配问题,本来使用了autolayout好好的,一个新同事拿到ios6.1上去一测,导航条和view中间空了一大截。
着了好多办法,最后发现苹果公司对iOS7.0专门设置了一个属性:
/*
 New behavior on iOS 7.
 Default is YES.
 You may force an opaque background by setting the property to NO.
 If the navigation bar has a custom background image, the default is inferred 
 from the alpha values of the image—YES if it has any pixel with alpha < 1.0
 If you send setTranslucent:YES to a bar with an opaque custom background image
 it will apply a system opacity less than 1.0 to the image.
 If you send setTranslucent:NO to a bar with a translucent custom background image
 it will provide an opaque background for the image using the bar's barTintColor if defined, or black
 for UIBarStyleBlack or white for UIBarStyleDefault if barTintColor is nil.
 
*/
@property(nonatomic,assign,getter=isTranslucent) BOOL translucent NS_AVAILABLE_IOS(3_0); // Default is NO on iOS 6 and earlier. Always YES if barStyle is set to UIBarStyleBlackTranslucent

好吧,问题就在这里。在代码中做一下系统版本判断,然后设置这个属性为NO。

一切就好了,哎,浪费时间啊!如果不改它,autolayout就会和你做对的。各位珍重.
//继承UINavigationController,加入一个实现
-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    //适配ios7
    if( ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 7.0)){
        self.navigationBar.translucent = NO;
    }
}
posted @ 2014-08-27 17:52 何清龙 阅读(6668) | 评论 (0) | 编辑 收藏
 
谈谈MVVM和MVC,使用swift集成RFP框架(ReactiveCocoa)
非常激动的和各位分享RFP的经验。目前国内使用swift开发实际项目的文章几乎还找不到,不用说ReactiveCocoa了。我打算把两个一起简单说一下。
MVC和MVVM的差异,我觉得对比实在是很细,重点是,MVVM的分割性更好,正交性强,而MVC在逻辑和试图代码方面经常混在一起,不能很好的模块化,以至于在多人开发的模式下,时不时出现逻辑混乱的情况。
另一个核心问题是,常规的编程思路在对象的依赖关系的维护方面基本无能为力。
我不想在一篇文章中扯一大把概念,MVVM的介绍和优点你可以自己去搜索。
这里是比较简洁的介绍

原来兴致冲冲的百度了一下swift RFP/RAC/MVVM,没实质性内容,干脆自己写一篇。
就谈谈在swift中使用MVVM吧,你可以去我的github仓库下载这里的完整代码.
RAC在object-c中的使用在github上有实例的。各位可以移步去看一下。

环境前提是你要有xcode6,pod管理器。这些工具你应该自己去找一下,当然你就用我的这个项目也行。
说一下集成步骤:
1.使用pod添加ReactiveCocoa到工程中,细节略。
2.打开编译xcworkspace,新建一个swift代码文件,在建立过程中,xcode会问你是不是要建立与object-c的混编中间头文件,选择是,并在这个头文件中加入RAC的头文件
#import <ReactiveCocoa/RACEXTScope.h>
#import <ReactiveCocoa/ReactiveCocoa.h>
以及你要使用的object-c的其他库的头文件
3.可以使用了,新建一个swift源文件,建立一个nib文件和它关联,然后设置一个button,代码类似这样:

@IOBullet button:UIButton = UIButton.buttonWithType(UIButtonType.Custom)
        button.rac_signalForControlEvents(UIControlEvents.TouchUpInside)
            .subscribeNext{
                _ in
                NSLog("按钮点击事件")
        }
//加入到UI层去
测试可以使用RAC了。点击这个按钮,打印内容就出来了
4.在swift中使用类似object-c中的RAC(button, hidden) = RACObserve(button2, hidden)是会出错的。需要自己实现,object-c中的RAC()这个宏很讨厌,想搞懂的可以网上查,我也记不清了。好了,我们来解决这个问题。
新建一个swift源码,最好叫ReactiveCocoa.swift,加入下面的代码:
//
//  ReactiveCocoa.swift
//  XianRenZhang
//
//  Created by kriswangw on 14/11/14.
//  Copyright (c) 2014年 kriswangw. All rights reserved.
//

public struct RAC  {
    var target : NSObject!
    var keyPath : String!
    var nilValue : AnyObject!
    
    init(_ target: NSObject!, _ keyPath: String, nilValue: AnyObject? = nil) {
        self.target = target
        self.keyPath = keyPath
        self.nilValue = nilValue
    }
    
    func assignSignal(signal : RACSignal) {
        signal.setKeyPath(self.keyPath, onObject: self.target, nilValue: self.nilValue)
    }
}

public func RACObserve(target: NSObject!, keyPath: NSString) -> RACSignal  {
    return target.rac_valuesForKeyPath(keyPath, observer: target)
}

public func <= (rac:RAC, signal:RACSignal){
    rac.assignSignal(signal)
}

public func >=( signal:RACSignal, rac:RAC){
    rac.assignSignal(signal)
}
然后我只要改变tableView的hidden属性,scrollView的属性就会跟着改变了,不用再去维护两个变量。
//两个按钮的点击切换不同的内容。
        self.changguan_btn.rac_signalForControlEvents(UIControlEvents.TouchUpInside)
            .subscribeNext {
                _ in
                self.tableView.hidden = true;
        }
        self.zhanpin_btn.rac_signalForControlEvents(UIControlEvents.TouchUpInside)
            .subscribeNext{
                _ in
                self.tableView.hidden = false;
        }

RAC的函数思想使得代码服用行更强,可以让我们把按钮的控制写成逻辑算法,而不是一个一个的重复的回调事件函数,或者含有多个链接nib文件的函数(不好维护)。
//TODO,修改为对应的UIViewController.也有可能是同一个ViewController,但是参数不同
        let ciqi_vc           = UIViewController()
        let yuqi_vc           = UIViewController()
        let huihua_vc         = UIViewController()
        let wenhuajiading_vc  = UIViewController()
        let zuke_vc           = UIViewController()
        let shufa_vc          = UIViewController()
        let qingtong_vc       = UIViewController()
        let keju_vc           = UIViewController()
        
        var btns2Actions: NSDictionary = [
            "瓷器":[self.qiciBtn, ciqi_vc],
            "玉器":[self.yuqiBtn, yuqi_vc],
            "绘画":[self.huihuaBtn, huihua_vc],
            "文化嘉定":[self.wenhuajiadingBtn, wenhuajiading_vc],
            "竹刻":[self.zukeBtn, zuke_vc],
            "书法":[self.shufaBtn, shufa_vc],
            "青铜":[self.qingtongBtn, qingtong_vc],
            "科举":[self.kejuBtn, keju_vc]]
        //定制每个button事件跳转的视图控制器。
        for (key : AnyObject, value : AnyObject ) in btns2Actions {
            let array = value as NSArray;
            let btn        = array[0] as UIButton;
            let vc:UIViewController = array[1] as UIViewController;
            btn.rac_signalForControlEvents(UIControlEvents.TouchUpInside)
                .subscribeNext { _ in
                    self.navigationController.pushViewController(vc, animated:false)
            }
        }
这段代码展示了使用抽象来统一所有事件响应的功能。每一个按钮对应的视图控制器都被绑定到一起了,如果新加入别的功能,代码仍然非常容易维护。所有功能相同的都放在了一起,约束性更强。

其他的RAC功能基本上默认就能使用,combineLatest也是可以直接使用的。记住swift中的所有方法调用都是"."下标符号,包括静态方法,init和隐式析够除外。

swift中没有#pragma宏,所以,它提供了这个注释风格(内置的)
// MARK:, // TODO: and // FIXME
可以达到和#pragma一样的效果
最后,swift和RFP都是非常好的东西,希望各位尽快用上,不然你要掉队了
posted @ 2014-08-05 11:29 何清龙 阅读(6570) | 评论 (5) | 编辑 收藏
 
仅列出标题
共7页: 1 2 3 4 5 6 7