小编use*_*510的帖子

我可以查看Objective-C中appendFormat实例方法的实现吗?

我想看看如何appendFormat在Objective-C中实现:

https://developer.apple.com/reference/foundation/nsmutablestring/1497308-appendformat

- (void)appendFormat:(NSString *)format, ...;
Run Code Online (Sandbox Code Playgroud)

有没有办法看一下实现?

我找到了这个:

https://github.com/cjwl/cocotron/blob/master/Foundation/NSString/NSMutableString.m#L111

-(void)appendFormat:(NSString *)format,... {
   NSString *string;
   NSRange   range={[self length],0};
   va_list   arguments;

   va_start(arguments,format);

   string=NSAutorelease(NSStringNewWithFormat(format,nil,arguments,NULL));
   va_end(arguments);

   [self replaceCharactersInRange:range withString:string];
}
Run Code Online (Sandbox Code Playgroud)

但我不确定是否与可可粉相同。

我想查看实现,以便可以确认运行时。由于appendFormat是用于可变字符串,因此我假设appendFormat的运行时是最坏的情况O(n)和摊销O(1),但我不确定。

(我不是Objective-C开发人员。)

cocoa objective-c

0
推荐指数
1
解决办法
101
查看次数

为什么使用 eval echo 会覆盖 bash 脚本中的环境变量?

我正在编写一个基于 CircleCI orb 源代码的 bash 脚本,我很困惑为什么 bash 脚本中的环境变量子集会被设置为eval echo它们自己。

例如,这条线的目的是什么?

ORB_EVAL_REPO=$(eval echo "${ORB_EVAL_REPO}")
Run Code Online (Sandbox Code Playgroud)

这是源代码:

https://circleci.com/developer/orbs/orb/circleci/aws-ecr#orb-source

作为一个完整的示例,第 705-709 行设置了五个环境变量,但eval echo在第 691-692 行仅使用其中两个变量进行设置,即使这些变量在第 699-702 行以相同的方式使用:

command: |
    #!/bin/bash
    ORB_EVAL_REGION=$(eval echo "${ORB_EVAL_REGION}") # line 691
    ORB_EVAL_REPO=$(eval echo "${ORB_EVAL_REPO}")

    if [ "$ORB_VAL_PUBLIC_REGISTRY" == "1" ]; then
        echo "set-repository-policy is not supported on public repos"
        exit 1
    else
        aws ecr set-repository-policy \
            --profile "${ORB_VAL_PROFILE_NAME}" \ # line 699
            --region "${ORB_EVAL_REGION}" \
            --repository-name "${ORB_EVAL_REPO}" \
            --policy-text "file://${ORB_VAL_REPO_POLICY_PATH}"
    fi
environment:
    ORB_EVAL_REGION: <<parameters.region>> # …
Run Code Online (Sandbox Code Playgroud)

bash eval circleci

0
推荐指数
1
解决办法
148
查看次数

标签 统计

bash ×1

circleci ×1

cocoa ×1

eval ×1

objective-c ×1