Light's Blog

The best or nothing.

iOS知识小集-170501

| Comments

ComponentKit Tutorial - CollectionView

Install

通过 Carthage 安装,在 Cartfile 中添加github "facebook/ComponentKit" ~> 0.20,然后运行carthage update,编译完成后,在 Embedded Binaries 添加Carthage/Build/iOS/ComponentKit.framework。所有需要使用ComponentKit的源文件需要修改后缀为 .mm

Philosophy

Doing so this reverses the traditional approach for a UICollectionViewDataSource. Usually the controller layer will tell the UICollectionView to update and then the UICollectionView ask the datasource for the data. Here the model is more Reactive, from an external prospective, the datasource is told what changes to apply and then tell the collection view to apply the corresponding changes.

iOS知识小集-170424

| Comments

ComponentKit Tutorial - Layout

Flexbox Layout

flex container:容器。
main axis:main start, main end。
cross axis:cross start, cross end。
flex item:成员。
main size。
cross size。

iOS知识小集-170417

| Comments

ComponentKit Tutorial - Component

CKComponent

A component is an immutable object that specifies how to configure a view, loosely inspired by React.

1
2
+ (instancetype)newWithView:(const CKComponentViewConfiguration &)view
                       size:(const CKComponentSize &)size;

Example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
CKComponent *component = [CKComponent
    newWithView:{
        [UIView class],
        {
            {@selector(setBackgroundColor:),[UIColor redColor]},
            {@selector(setUserInteractionEnabled:), @YES},
            {CKComponentTapGestureAttribute(@selector(didTap))},
            {CKComponentViewAttribute::LayerAttribute(@selector(setCornerRadius:)), @10.0}
        }
    }
    size:{50,50}];

- (void)didTap{
  [self updateState:^(NSNumber *oldState){
    return [oldState boolValue] ? @NO : @YES;
  } mode:CKUpdateModeSynchronous];
}

iOS知识小集-170410

| Comments

ComponentKit Tutorial - Introduction

Philosophy

Components are immutable objects that specify how to configure views.
Declarative : You declare the subcomponents of your component.
Functional : Data flows in one direction.
Composable : Reusing it is a one-liner.

iOS知识小集-170403

| Comments

Heap and Stack

Value types are created on the stack, Reference types are created on the heap.
Stack is attached to a thread, and Heap is attached to the application.
Stack is faster than Heap.

iOS知识小集-170327

| Comments

转换

NSURL -> NSString:NSString *path = [url path];
NSString -> NSURL:NSURL *url = [NSURL fileURLWithPath:path];
UIImage -> NSData:NSData *data = UIImagePNGRepresentation(image);
NSData -> UIImage:UIImage *image = [UIImage imageWithData:data];