文章出处,原创于 https://HawkingOuYang.github.io/
深拷贝、浅拷贝
Deep copying an NSArray
http://stackoverflow.com/questions/647260/deep-copying-an-nsarray
If you only need a one-level-deep copy, you can explicitly call for one…
NSMutableArray *newArray = [[NSMutableArray alloc] initWithArray:oldArray copyItems:YES];
If you need a true deep copy, such as when you have an array of arrays, you can archive and then unarchive the collection, provided the contents all conform to the NSCoding protocol. An example of this technique is shown in Listing 3.
Listing 3 A true deep copy
NSArray* trueDeepCopyArray = [NSKeyedUnarchiver unarchiveObjectWithData:
[NSKeyedArchiver archivedDataWithRootObject:oldArray]];
{//[begin] fix bug — A true deep copy
/*
http://stackoverflow.com/questions/647260/deep-copying-an-nsarray
If you need a true deep copy, such as when you have an array of arrays, you can archive and then unarchive the collection, provided the contents all conform to the NSCoding protocol. An example of this technique is shown in Listing 3.
Listing 3 A true deep copy
NSArray* trueDeepCopyArray = [NSKeyedUnarchiver unarchiveObjectWithData:
[NSKeyedArchiver archivedDataWithRootObject:oldArray]];
*/
ONOXMLElement *deepCopyElement = [NSKeyedUnarchiver unarchiveObjectWithData:
[NSKeyedArchiver archivedDataWithRootObject:element]];
//TODO: ONOXMLElement实现了NSCoding协议,unarchiveObjectWithData时 为何崩溃?
self.element = deepCopyElement;//strong reference
}//[end] fix bug — A true deep copy
TODO: 这里还需要一张图片 !!
/ 码字–开始 /
//from - immutable And mutable
NSString str1 = @”str1”;
NSMutableString mutableStr1 = [NSMutableString stringWithString:@”mutableStr1”];
NSArray arr1 = [ NSArray arrayWithObjects:@”1”,@”2”,@”3”, nil];
NSMutableArray mutableArr1 = [NSMutableArray arrayWithObjects:@”A”,@”B”,@”C”, nil];
//to - inmutable
NSString copyStr1 = [str1 copy];
NSString mutableCopyStr1 = [str1 mutableCopy];
NSString copyMutableStr1 = [mutableStr1 copy];
NSString mutablecopyMutableStr1 = [mutableStr1 mutableCopy];
//to - mutable
NSMutableString copyStr1ToM = [str1 copy];
NSMutableString mutableCopyStr1ToM = [str1 mutableCopy];
NSMutableString copyMutableStr1ToM = [mutableStr1 copy];
NSMutableString mutablecopyMutableStrToM = [mutableStr1 mutableCopy];
//log
NSLog(@”copyStr1=%p,%@—-from—str1=%p,%@”,
copyStr1,copyStr1, str1,str1);
NSLog(@”mutableCopyStr1=%p,%@————from—str1=%p,%@”,
mutableCopyStr1,mutableCopyStr1, str1,str1);
NSLog(@”copyMutableStr1=%p,%@————from—mutableStr1=%p,%@”,
copyMutableStr1,copyMutableStr1, mutableStr1,mutableStr1);
NSLog(@”mutablecopyMutableStr1=%p,%@————–from—mutableStr1=%p,%@”,
mutablecopyMutableStr1,mutablecopyMutableStr1, mutableStr1,mutableStr1);
NSLog(@”copyStr1ToM=%p,%@———from—str1=%p,%@”,
copyStr1ToM,copyStr1ToM, str1,str1);
NSLog(@”mutableCopyStr1ToM=%p,%@—————from—str1=%p,%@”,
mutableCopyStr1ToM,mutableCopyStr1ToM, str1,str1);
NSLog(@”copyMutableStr1ToM=%p,%@—————from—mutableStr1=%p,%@”,
copyMutableStr1ToM,copyMutableStr1ToM, mutableStr1,mutableStr1);
NSLog(@”mutablecopyMutableStrToM=%p,%@———————from–mutableStr1=%p,%@”,
mutablecopyMutableStrToM,mutablecopyMutableStrToM, mutableStr1,mutableStr1);
/ 码字–好累 /
2014-11-27 14:02:20.437 TestCopy[466:6731] copyStr1=0x100001088,str1—-from—str1=0x100001088,str1
2014-11-27 14:02:20.439 TestCopy[466:6731] mutableCopyStr1=0x100206420,str1————from—str1=0x100001088,str1
2014-11-27 14:02:20.440 TestCopy[466:6731] copyMutableStr1=0x100206500,mutableStr1————from—mutableStr1=0x100204d80,mutableStr1
2014-11-27 14:02:20.440 TestCopy[466:6731] mutablecopyMutableStr1=0x100206520,mutableStr1————–from—mutableStr1=0x100204d80,mutableStr1
2014-11-27 14:02:20.441 TestCopy[466:6731] copyStr1ToM=0x100001088,str1———from—str1=0x100001088,str1
2014-11-27 14:02:20.441 TestCopy[466:6731] mutableCopyStr1ToM=0x100206580,str1—————from—str1=0x100001088,str1
2014-11-27 14:02:20.441 TestCopy[466:6731] copyMutableStr1ToM=0x1002065e0,mutableStr1—————from—mutableStr1=0x100204d80,mutableStr1
2014-11-27 14:02:20.441 TestCopy[466:6731] mutablecopyMutableStrToM=0x100206600,mutableStr1———————from–mutableStr1=0x100204d80,mutableStr1
Program ended with exit code: 0
app 修改hosts
#pragma mark - 同步联系人
/*
因为:直接访问测试地址
(即ip地址)不行;
那么:需要修改本地hosts
(即设置每个request实例的host);
这么做:
#if defined( DEBUG )
[request setValue:@”example.domain.com” forHTTPHeaderField:@”host”];//修改本地hosts
#endif
所以,这样,客户端使用域名访问
。
*/
//! 同步联系人,基于 WebDAV 协议
#if defined( DEBUG )
static NSString const kBaseURL_syncContact = @”http://255.255.255.100/“; //测试环境
static NSString const kURL_syncContactInfo = @”sync/contact”;
#else
static NSString const kBaseURL_syncContact = @”http://example.domain.com/“; //生产环境
static NSString const kURL_syncContactInfo = @”sync/contact”;
#endif
#if defined( DEBUG )
// TODO: test code
[request setValue:@”example.domain.com” forHTTPHeaderField:@”host”];
#endif
tableView 性能优化
Cell圆角
方式一:layer 设置圆形,重绘
|
|
这个不太靠谱。
方式二:圆形 layer,填充图片
Fastest way to do shadows on iOS?
Performance scrolling and retina resolution images in CALayer
bharath2020/UITableViewTricks 这个很好!
|
|
cell搜索匹配高亮
cell动态高度
cell动态内容
table批更新
tableView batch update
How to detect that animation has ended on UITableView beginUpdates/endUpdates? (这个 好呀)
Batch updates for UITableView and UICollectionView (这个 好呀)
TableView reloadData vs. beginUpdates & endUpdates
layoutSubviews
When does layoutSubviews get called?
It’s important to optimize any UIView layoutSubviews method you create, as it can be frequently called, and has the potential for creating recursion (triggering a setNeedsLayout from layoutSubviews can create a loop that will grossly affect your apps performance). Layout subviews is called once per run loop on any view that has had setNeedsLayout or setNeedsDisplayWithRect: called on it. So in addition to any time you manually call these methods, it can be useful to know when the UI framework calls setNeedsLayout/setNeedsDisplay as this will trigger layoutSubviews.
For this purpose, I will define a few view relationships:
- View1 – UIView class, root view for examples
- View1.1 – UIScrollView class, subview of View1
- View1.1.1 – UIView class, subview of View1.1 (No autoresize mask)
- View1.1.2 – UIView class, another subview of View1.1 (Autoresize mask – flexible width)
I then ran the following tests. An X means the view was layed out
//TODO: layoutSubviews 图片
From this I surmise the following:
- init does not cause layoutSubviews to be called (duh)
- addSubview causes layoutSubviews to be called on the view being added, the view it’s being added to (target view), and all the subviews of the target view
- setFrame intelligently calls layoutSubviews on the view having it’s frame set only if the size parameter of the frame is different
- scrolling a UIScrollView causes layoutSubviews to be called on the scrollView, and it’s superview
- rotating a device only calls layoutSubview on the parent view (the responding viewControllers primary view)
- removeFromSuperview – layoutSubviews is called on superview only (not show in table)
Hopefully this is helpful information for you as well.
英文:When is layoutSubviews called?
http://stackoverflow.com/questions/728372/when-is-layoutsubviews-called
中文:什么时候调用layoutSubviews
http://blog.csdn.net/hopedark/article/details/24313445
I had a similar question, but wasn’t satisfied with the answer (or any I could find on the net), so I tried it in practice and here is what I got:
- init does not cause layoutSubviews to be called (duh)
- addSubview: causes layoutSubviews to be called on the view being added, the view it’s being added to (target view), and all the subviews of the target
- view setFrame intelligently calls layoutSubviews on the view having its frame set only if the size parameter of the frame is different
- scrolling a UIScrollView causes layoutSubviews to be called on the scrollView, and its superview
- rotating a device only calls layoutSubview on the parent view (the responding viewControllers primary view)
- Resizing a view will call layoutSubviews on its superview
今天在写程序时候遇见layoutSubviews触发时候引起的问题。特来总结一下什么时候会触发layoutSubviews:
layoutSubviews在以下情况下会被调用:
1、init初始化不会触发layoutSubviews
2、addSubview会触发layoutSubviews
3、设置view的Frame会触发layoutSubviews,当然前提是frame的值设置前后发生了变化
4、滚动一个UIScrollView会触发layoutSubviews
5、旋转Screen会触发父UIView上的layoutSubviews事件
6、改变一个UIView大小的时候也会触发父UIView上的layoutSubviews事件
网络回调
What exactly is RESTful programming?
网络回调方式总结:
1、代理
2、通知
3、代码块
4、IMP
代理
优点:效率高
缺点:代码耦合度高,若一个Controller有多个网络请求,响应同一个代理方法,代码将变得臃肿难看
通知
优点:代码耦合度低,简单
缺点:多对多,容易滥用,不易控制,释放不及时可能导致通知方法调用多次,不易维护
代码块
优点:耦合度低,效率较高,代码更优雅
缺点:块会延迟对象的生命周期,占用较多的内存,使用不当会造成内存泄露,以及循环引用
IMP
优点:耦合度低
缺点:编译时不会错误检查(如方法名错误等),不易维护
iOS
Why isn’t ProjectName-Prefix.pch created automatically in Xcode 6?
//TODO: 插入图片
|
|
Xcode 5: Test UITableView with XCTest framework
dispatch_group_notify does not wait for one dispatch_group_async (这个好)
Getting Download progress with AFNetworking 2.0 + NSProgress + Custom ProgressView
AFHTTPRequestOperationManager post multi-part request not working (这个好呀)
How to set HTTP request body using AFNetwork’s AFHTTPRequestOperationManager?
send image along with other parameters with AFNetworking
AFNetworking 2: How to cancel a AFHTTPRequestOperationManager request?
AFNetworking 2.0 // How to read response header
Afnetworking 2 with parameters
iOS图片加载速度极限优化—FastImageCache解析
What is the difference between NS_ENUM and NS_OPTIONS?
Linux (Mac 类Unix)
Why is FreeBSD deprecating GCC in favor of Clang/LLVM?
Clang vs GCC for my Linux Development project
LLVM vs. GCC for iOS development
What features does Darwin have that other Unixes don’t, or vice versa?
Where does Mac OS X come from?
How close are Mac OS X and BSD related?
multi-CPU, multi-core, and hyper-thread
SSH with Public Key-Based Authentication
安装macvim
安装Homebrew:打开“终端”程序,输入
gem brew ruby pod
Operation not permitted - /usr/bin/update_rubygems
关键:sudo gem install -n /usr/local/bin GEM_NAME_HERE
/usr/bin vs /usr/local/bin on Linux (只关注: /usr/local/bin 即可)
Homebrew 是 The missing package manager for OS X,
Homebrew installs packages to their own directory and then symlinks their files into /usr/local.