小编Ric*_*hiy的帖子

Xcodebuild - 跳过完成请求崩溃报告。继续测试

我正在使用 Xcode 运行 CI 机器。

测试是使用触发的fastlane gym。我在输出中看到这一行:

2019-05-27 16:04:28.417 xcodebuild[54605:1482269] [MT] IDETestOperationsObserverDebug: (A72DBEA3-D13E-487E-9D04-5600243FF617) 完成请求崩溃报告。继续测试。

此操作需要一些时间(大约一分钟)才能完成。据我所知,Xcode 请求 Apple 的崩溃报告显示在“组织者”窗口中。

由于这是一台 CI 机器,因此永远不会在其上查看崩溃报告,这一步可以完全跳过,我怎么能跳过它?

xcode xcodebuild ios fastlane fastlane-gym

20
推荐指数
1
解决办法
1613
查看次数

按索引移位数组中的元素

给定n个元素的数组,即

var array = [1, 2, 3, 4, 5]

我可以写一个扩展名,Array所以我可以修改数组来实现这个输出[2, 3, 4, 5, 1]:

mutating func shiftRight() {
  append(removeFirst())
}
Run Code Online (Sandbox Code Playgroud)

有没有办法实现这样一个函数,可以通过任何索引,正面或负面移动数组.我可以使用if-else子句以命令式样式实现此函数,但我正在寻找的是功能实现.

算法很简单:

  1. 通过提供的索引将数组拆分为两个
  2. 将第一个数组追加到第二个数组的末尾

有没有办法在功能风格中实现它?

我完成的代码:

extension Array {
  mutating func shift(var amount: Int) {
    guard -count...count ~= amount else { return }
    if amount < 0 { amount += count }
    self = Array(self[amount ..< count] + self[0 ..< amount])
  }
}
Run Code Online (Sandbox Code Playgroud)

arrays generics ios swift

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

Siri Custom Intent:"快捷方式"应用程序中的变量

我创建了一个自定义Siri意图.它在"快捷方式"应用程序中可见.但是,它允许我仅从捐赠的快捷方式中选择,而无需指定自己的参数.

是否可以使用"快捷方式"应用程序创建支持提供参数的Siri Intent?

我的意图配置

在此输入图像描述

结果如何:

在此输入图像描述

我想要实现的目标

请注意,如何预先填写字段(例如Item字段).我想有相同的选择phoneNumber.

在此输入图像描述

ios siri swift sirikit sirishortcuts

13
推荐指数
1
解决办法
624
查看次数

Xcode仪器:泄漏 - 应用程序在发布时崩溃

Xcode仪器:泄漏 - 应用程序在发布时崩溃

应用程序在设备和模拟器中都崩溃了.

什么可能导致应用程序与附加的仪器一起崩溃,同时使用电缆安装或通过Fabric通过空中正常工作.

更新:使用"泄漏"选项卡启动"分配"工具有助于: 在此输入图像描述

xcode memory-leaks ios xcode-instruments

12
推荐指数
2
解决办法
3281
查看次数

GitLab CI:两个独立的预定作业

考虑以下gilab-ci.yml脚本:

stages:
  - build_for_ui_automation
  - independent_job

variables:
  LC_ALL: "en_US.UTF-8"
  LANG: "en_US.UTF-8"

before_script:
  - gem install bundler
  - bundle install

build_for_ui_automation:
  dependencies: []
  stage: build_for_ui_automation
  artifacts:
    paths:
      - fastlane/screenshots
      - fastlane/logs
      - fastlane/test_output
      - fastlane/report.xml
  script:
    - bundle exec fastlane ui_automation
  tags:
    - ios
  only:
    - schedules
  allow_failure: false

# This should be added and trigerred independently from "build_for_ui_automation"
independent_job:
  dependencies: []
  stage: independent_job
  artifacts:
    paths:
      - fastlane/screenshots
      - fastlane/logs
      - fastlane/test_output
      - fastlane/report.xml
  script:
    - bundle exec fastlane …
Run Code Online (Sandbox Code Playgroud)

gitlab gitlab-ci gitlab-ci-runner gitlab-ce

9
推荐指数
2
解决办法
3803
查看次数

使用两个静态库(libssl.a、libcrypto.a)创建 XCFramework

考虑 OpenSSL,该项目本身有两个产品:libssl.alibcrypto.a。为了简单起见,我们使用存储在该存储库中的预编译库并仅考虑iphonesimulator平台。

当查看存储库时,每个平台例如iphonesimulatoriphoneos将具有一组用于所有所需架构的静态库。

我的目标是创建一个捆绑这两个静态库的 XCFramework,以便可以方便地将 Swift Package Manager 作为单个包使用。

我绝对可以使用以下命令从静态库创建一个支持多个平台的 XCFramework:iOS Simulator ( i386, x86_64, arm64), iOS ( arm64, ...) :arm7

xcodebuild -create-xcframework \
-library iphonesimulator/lib/libcrypto.a \
-headers iphonesimulator/include/ \
-library iphoneos/lib/libcrypto.a \
-headers iphoneos/include/ \
-output OpenSSL.xcframework
Run Code Online (Sandbox Code Playgroud)

输出如下:

xcframework 成功写入:/Users/name/OSSL_test/OpenSSL.xcframework

框架的结构是正确的,它包含标头和libcrypto.a. 当导入到另一个 Xcode 项目时,该 XCFramework 会被识别并用于构建应用程序。

但是,当我也尝试添加时libssl.a,出现以下错误:

xcodebuild -create-xcframework \
-library iphonesimulator/lib/libcrypto.a \
-headers iphonesimulator/include/ \
-library iphonesimulator/lib/libssl.a …
Run Code Online (Sandbox Code Playgroud)

openssl static-libraries ios libcrypto xcframework

9
推荐指数
1
解决办法
4726
查看次数

在UICollectionViewFlowLayout中启用AutoSizing单元格时,DecorationView会调整大小

环境:
UICollectionView看起来像UITableView的
自定义UICollectionViewFlowLayout子类来定义frame的的DecorationView
启用自调整大小细胞

预期行为:
A DecorationView应该作为背景放置在每个部分UICollectionView

预期的行为

观察到的行为:
DecorationView崩溃到任意尺寸:

观察到的行为

似乎UICollectionView试图计算自动大小DecorationView.如果我禁用Self-Sizing单元格,则装饰视图将精确放置在预期位置.

有没有办法禁用Self-Sizing DecorationView

在我的UICollectionViewFlowLayout子类中,我只需要截取该部分中的第一个和最后一个单元格并拉伸背景以填充它们下面的空间.问题是UICollectionView不考虑那里计算的大小:

override func layoutAttributesForDecorationView(ofKind elementKind: String, at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
    guard let collectionView = collectionView else {
      return nil
    }

    let section = indexPath.section
    let attrs = UICollectionViewLayoutAttributes(forDecorationViewOfKind: backgroundViewClass.reuseIdentifier(),
                                                 with: indexPath)
    let numberOfItems = collectionView.numberOfItems(inSection: section)
    let lastIndex = numberOfItems - 1

    guard let firstItemAttributes = layoutAttributesForItem(at: IndexPath(indexes: [section, …
Run Code Online (Sandbox Code Playgroud)

ios autolayout uicollectionview swift uicollectionviewflowlayout

8
推荐指数
1
解决办法
319
查看次数

在 Swift 中使用 NSProxy

如何NSProxy在 Swift 中创建子类?

尝试添加任何init方法都会失败并出现错误:“无法在初始化程序之外调用超级初始化”或“从初始化程序返回之前,不会在所有路径上调用超级初始化”

错误1 错误2

使用 Objective-C 子类作为基类是可行的,但感觉更像是一种 hack:

// Create a base class to use instead of `NSProxy`
@interface WorkingProxyBaseClass : NSProxy
- (instancetype)init;
@end

@implementation WorkingProxyBaseClass
- (instancetype)init
{
  if (self) {

  }
  return self;
}
@end



// Use the newly created Base class to inherit from in Swift
import Foundation

class TestProxy: WorkingProxyBaseClass {
  override init() {
    super.init()
  }
}
Run Code Online (Sandbox Code Playgroud)

proxy-pattern nsproxy swift

8
推荐指数
1
解决办法
2630
查看次数

Swift 包中与平台相关的文件

我正在开发一个支持 iOS 和 macOS 的跨平台 C++ 库。可以使用 Swift Package Manager 集成该库。在 C++ 中,很容易拥有一个头文件和多个不同的实现文件,这些文件将为每个平台进行编译。例如,标头有一个print()方法,每个目标以不同的方式实现它:

macOS: "print_macOS"
iOS: "print_iOS"
Windows: "print_Windows"
Run Code Online (Sandbox Code Playgroud)

是否有可能以某种方式使 Swift Package Manager 根据平台有条件地包含/排除目标中的特定文件?

我发现的最接近的功能是条件目标依赖项,但它涉及包含/排除特定库而不仅仅是文件。我需要有更细粒度的方法。

目前我正在使用编译时指令来解决此问题:

#include "Print.h"

std::string Print::PrintMethod()
{
#if TARGET_OS_IPHONE
    return "print_iOS";
#else
    return "print_macOS";
#endif
}
Run Code Online (Sandbox Code Playgroud)

那么,有没有什么方法可以用不同的文件实现相同的结果呢?请注意,除了这两个文件之外,两个平台(iOS 和 macOS)的目标完全相同。

参考Package.swift文件:

// swift-tools-version:5.4
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "ResultingTarget",
    platforms: [
        .iOS(.v13), .macOS(.v10_15)
    ],
    products: …
Run Code Online (Sandbox Code Playgroud)

c++ macos ios swift swift-package-manager

8
推荐指数
0
解决办法
483
查看次数

组合sink:忽略receiveValue,只需要completion

考虑以下代码:

        CurrentValueSubject<Void, Error>(())
            .eraseToAnyPublisher()
            .sink { completion in

                switch completion {
                case .failure(let error):
                    print(error)
                    print("FAILURE")
                case .finished:
                    print("SUCCESS")
                }
            } receiveValue: { value in
                // this should be ignored
            }
Run Code Online (Sandbox Code Playgroud)

只需查看CurrentValueSubject初始值设定项,就可以清楚地看出该值不需要/无关紧要。

我正在使用这个特定的发布者发出异步网络请求,该请求可能会通过也可能会失败。

由于我对此发布者返回的值不感兴趣(没有),我怎样才能摆脱闭receiveValue包?

理想情况下,调用站点代码应如下所示:

        CurrentValueSubject<Void, Error>(())
            .eraseToAnyPublisher()
            .sink { completion in

                switch completion {
                case .failure(let error):
                    print(error)
                    print("FAILURE")
                case .finished:
                    print("SUCCESS ")
                }
            }
Run Code Online (Sandbox Code Playgroud)

也可能是我应该使用不同于 的东西AnyPublisher,所以如果它更适合目的,请随意提议/重写 API。

我能找到的最接近的解决方案是ignoreOutput,但它仍然返回一个值。

reactive-programming swift swiftui combine

8
推荐指数
2
解决办法
6409
查看次数