小编Jon*_*eon的帖子

通过自动布局使用UIScrollView中的顶部布局指南

我想Top Layout GuideUIScrollView直通自动布局中使用.没有UIScrollView自动布局可以很好地使用Top Layout Guide. 在此输入图像描述

但是当我嵌入UIButtonUIScrollView,它没有. 在此输入图像描述

我知道那是因为UIScrollView与层次结构级别不同Top Layout Guide.但我认为解决这个问题可能有一个很好的解决方案.

interface-builder uiscrollview ios autolayout

7
推荐指数
2
解决办法
5113
查看次数

你有没有听过"位置"的设计模式?

在这些日子里,我正在研究数据结构.在我的数据结构书中,作者说,"我们将使用'位置'设计模式" - > 照片

所以我用谷歌搜索了位置设计模式,因为我想知道它.但是,我找不到任何结果.:'(

作者说,"我们使用位置设计模式的原因是我们不希望允许用户修改内部结构." - > 照片1 照片2
(例如,当我们返回节点元素时,不显示访问链接的方法)

我绝对同意作者的意见和意图,但我无法确定"设计模式"这个词

design-patterns data-structures

6
推荐指数
1
解决办法
394
查看次数

为什么iOS中的某些库是由基于C的API提供的?

为什么iOS中的某些库提供了基于C的API?例如,Core Graphics库由基于C的API提供.但是,我无法理解Apple之所以这样做的原因.

而且,[[UIColor red] setStroke]drawRect中的那种代码:也让我感到困惑!如果Apple决定使用基于C的API,为什么他们使用面向对象的样式代码来做图形事情呢?

并且CGContextAddLineToPoint(),例如,进行论证CGContextRef c.我认为它完全适合使用面向对象的东西.

// current
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextMoveToPoint(context, 0, 0);
CGContextAddLineToPoint(context, 10, 10);

// looks better
CGContext *context = [UIGraphics getCurrentContext]
[context moveToPoint: CGMakePoint(0, 0)] // or [context moveToPointX: 0 y: 0]
[context addLineToPoint: CGMakePoint(10, 10)]  // or [context addLineToPointX: 10 y: 10]
Run Code Online (Sandbox Code Playgroud)

那么,为什么Apple在某些库上使用基于C的API?

core-graphics objective-c ios

3
推荐指数
2
解决办法
1062
查看次数

许多参数的最佳实践方法

我正在编写一个需要很多参数的注册方法.最初,我为我的方法选择了以下方法.

// APPROACH #1
- (void)signUpWithInformation:(NSDictionary *)information
                      success:(void (^)(NSDictionary *))success
                      failure:(void (^)(NSError *))failure
{
    // ...

    NSDictionary *parameters = @{@"email": information[@"email"],
                                 @"new_password": information[@"password"],
                                 @"user_name": information[@"username"],
                                 @"sex": ([information[@"sex"] isEqualToNumber:@(EFTUserSexMale)]) ? @"M" : @"F",
                                 @"phone_nubmer": information[@"phoneNumber"],
                                 @"weight": information[@"weight"],
                                 @"height": information[@"height"],
                                 @"birthday": [formatter stringFromDate:information[@"birthday"]]};

    // ...
}
Run Code Online (Sandbox Code Playgroud)

但我觉得这种方法有些不适.虽然information给了我一些灵活性,但它需要装箱和拆箱来将值存储到字典中.

所以我想到了以下方法.

// APPROACH #2
- (void)signUpWithEmail:(NSString *)email
               password:(NSString *)password
                   name:(NSString *)name
                    sex:(EFTUserSex)sex
            phoneNumber:(NSString *)phoneNumber
                 weight:(double)weight
                 height:(double)height
               birthday:(NSDate *)birthday
                success:(void (^)(NSDictionary *))success
                failure:(void (^)(NSError *))failure
{
    // ...

    NSDictionary *parameters = @{@"email": email,
                                 @"new_password": …
Run Code Online (Sandbox Code Playgroud)

objective-c

3
推荐指数
1
解决办法
64
查看次数

哪个变量名称合适?

我想制作一个变量,这是客户想要的调味品.

我以为'condimentCustomerWants'没问题

但我永远不会在其他代码中看到包含相对代词的变量名.

所以我问我的朋友,他推荐'customerWantsCondiment',这是一句话.

嗯......哪个名字合适,好,可读?

convention variables naming

2
推荐指数
1
解决办法
717
查看次数