小编use*_*191的帖子

如何使用@testable导入带空格的模块

听起来像一个愚蠢的问题,但我想知道如何导入带空格的模块?

我正在关注链接添加测试用例,但我的项目有一个空格foo bar.那么我应该如何导入使用@testable

@testable import foo bar 抛出错误

ui-testing ios swift xcode7

16
推荐指数
1
解决办法
1621
查看次数

Xcode 不允许我在 SPM 中添加时指定文件名

我的项目中有一个独立的 SPM(本地)。当我向此包添加任何新文件时,Xcode 不会显示指定名称的提示。通常,当在项目中添加文件时,它会请求允许指定名称的位置。但是当添加 SPM 时,它会立即创建一个带有File.swiftalways的文件。

我不介意重命名,但只是标题也有一个通用的File.swift

//
//  File.swift
//  
//
//  Created by McDuck, Scrooge on 02/06/89.
//
Run Code Online (Sandbox Code Playgroud)

有什么解决方法吗?

我也尝试过 Xcode 13.4

xcode swift-package-manager

11
推荐指数
1
解决办法
1845
查看次数

如何以编程方式添加与Autolayout的InputAccessoryView?

我正在尝试添加一个UIView带有"完成"按钮作为文本字段的输入附件视图.

        let view = UIView()
        let doneButton = UIButton(type: .Custom)
        doneButton.setTitle("Done", forState: .Normal)
        doneButton.translatesAutoresizingMaskIntoConstraints = false
        view.addSubview(doneButton)
        view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:[button]-|", options: NSLayoutFormatOptions.DirectionLeadingToTrailing, metrics: nil, views: ["button":doneButton]))
        view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[button]|", options: NSLayoutFormatOptions.DirectionLeadingToTrailing, metrics: nil, views: ["button":doneButton]))
        view.addConstraint(NSLayoutConstraint(item: view, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: doneButton, attribute: NSLayoutAttribute.Height, multiplier: 1, constant: 0)) // Even this does not work
        self.emailTextField.inputAccessoryView = view
Run Code Online (Sandbox Code Playgroud)

但是,我无法在Xcode中看到视图高度设置和视图层次结构调试器/检查器中的按钮.

但是,如果我通过设置其框架添加视图,我可以看到添加的视图.我也尝试将高度约束强制设置为常数21,它打破了一些我没有添加的其他约束_UIKBAutolayoutHeightConstraint

"<NSLayoutConstraint:0x7fa3c962be50 UIView:0x7fa3c963bf60.height == UIButton:0x7fa3c963c0d0.height + 21>",
    "<NSLayoutConstraint:0x7fa3c95e0a90 '_UIKBAutolayoutHeightConstraint' V:[UIView:0x7fa3c963bf60(0)]>"
Run Code Online (Sandbox Code Playgroud)

以前有人遇到过这个问题吗?

ios inputaccessoryview swift ios-autolayout

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

如何使用日期格式化程序仅显示分钟为零的小时数?

我目前使用该格式MM-dd-yyyy HH:mm来显示时间戳。如果时间没有任何分钟组件,是否可以删除分钟?

像,而不是3:00 PM可以只显示3 PM

编辑:

func formatDate(_ dateFormat: String, timeInterval: TimeInterval) -> String {
    let date = Date(timeIntervalSince1970: timeInterval)
    let formatter = DateFormatter()

    formatter.dateFormat = dateFormat
    return formatter.string(from: date) 
}

let formattedDate = formatDate("MM-dd-yyyy HH:mm", timeInterval: 1520422200)
print(formattedDate)
Run Code Online (Sandbox Code Playgroud)

swift

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