小编Hon*_*ney的帖子

以编程方式更新通过Inspector设置的Autolayout约束

我有一个ViewController,里面有一个tableview.我手动设置了自动布局.现在我试图以编程方式更改自动布局约束.我怎样才能做到这一点?

这是我的代码截图

谢谢

ios swift

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

更改为Swift 3的UIViewControllerTransitioningDelegate定义可防止转换

我一直在按照教程添加为Swift 2编写的自定义转换:但我的自定义转换不会替换现有转换.

transition viewcontroller ios swift

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

在 Xcode 中搜索多个字符串

有什么方法可以string1 || string2在我的 Xcode 项目和/或单个文件中搜索类似的内容吗?

这样做时,我希望 Xcode 在找到string1OR 的任何地方突出显示string2

regex xcode find

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

Swift 3 单元测试抛出编译错误“无法将值‘类型’转换为‘类型’”

我有一个结构(部分)

struct Event : JSONSerializable, Glossy {
    let name : String
    let start : String
    private var startTimeZone: String
    let finish : String
    private var finishTimeZone: String
Run Code Online (Sandbox Code Playgroud)

从 UnitTest 调用时:

func testReal() {
    let event : Event = Event()
    let editor = EventEditor(forEvent: Event())
    XCTAssertNotNil(editor)
}
Run Code Online (Sandbox Code Playgroud)

引发编译错误:无法将“事件”类型的值转换为预期的争论类型“事件”

事件编辑器是:

import Foundation

class EventEditor {
let event : Event

   init(forEvent event: Event) {
        self.event = event
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,如果从产品(也称为单元测试外部)调用时,它可以正常工作,没有错误或问题。JSONSerializable——用于转换为/从 JSON Glossy 的辅助扩展——用于 json 解析的 cocoapod。

我尝试创建一个精简版的 Event 并添加部分(例如 JSONSerializable、Glossy)

谁能建议为什么这在 XCTest 中不起作用但在其他代码中起作用?

xcode struct initialization xctest swift

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

有没有办法将元素/值附加到元组?

反正有没有为元组添加新元素?

var tuple = (v1: 1,v2: 2)

tuple.v3 = 3 // Error
Run Code Online (Sandbox Code Playgroud)

"错误:元组类型的值'(v1:Int,v2:Int)'没有成员'v3'"

tuples swift

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

Swift:从 AppDelegate 中的 UNTextInputNotificationAction 获取内容

我正在使用Xcode 9.4.1 (9F2000)Swift

我有这个代码AppDelegate

func showPushButtons(){
    let replyAction = UNTextInputNotificationAction(
        identifier: "reply.action",
        title: "Reply to message",
        textInputButtonTitle: "Send",
        textInputPlaceholder: "Input text here")

    let pushNotificationButtons = UNNotificationCategory(
        identifier: "allreply.action",
        actions: [replyAction],
        intentIdentifiers: [],
        options: [])

    UNUserNotificationCenter.current().setNotificationCategories([pushNotificationButtons])
}
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {

    let action = response.actionIdentifier
    let request = response.notification.request
    let content = response.notification.request.content.userInfo

    print("\(action)\(request)\(content)")

    if let aps = content["aps"] as? [String: AnyObject] {
        dump(aps)
    } …
Run Code Online (Sandbox Code Playgroud)

xcode apple-push-notifications ios swift unusernotificationcenter

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

在swift中键入String()和String.self有什么区别?

我有点卡住试图.self在swift中理解,总是我在collectionView或tableView中注册一个自定义单元格我必须注册,customCollectionViewCell.self但为什么不是例如customCollectionViewCell()

我已经在操场上尝试输入String.selfvar以查看发生了什么并且它没有给我任何错误但是当我尝试给它一个值时它会给我以下错误

无法为类型指定"String"类型的值 String.Type

这是什么意思?

uitableview swift

-1
推荐指数
1
解决办法
137
查看次数

如何在dateFormatter中添加字符

我按照这个答案,但它对我不起作用.

我想把我的时间格式化为:

"2017-09-11 T 11:45:00-04:00"

我正在做:

let xFormatter = DateFormatter()
xFormatter.dateFormat = "yyyy-MM-ddTHH:mm:ss-04:00"
print(xFormatter.string(from: date))
Run Code Online (Sandbox Code Playgroud)

我需要一个日期和时间之间的T. 但是,如果我添加它,我的格式变成如下:

2017年9月11日

(最后-4:00是我硬编码的时间偏移...)

date swift

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

为什么在闭包完成相同的函数之前执行延迟块

我在Swift 2.0中编写了以下函数来添加一个地图注释,用于CLGeocoder()解析给定坐标的位置名称.我使用一个defer块来获取已解析的位置名称,但是,在闭包完成之前,延迟块似乎已完成.为什么?

以下是我的代码:

func addAnnotation(gestureRecognizer: UIGestureRecognizer) {
    var locationNameStr = ""
    defer {
        let newPin = Pin(dictionary: locationDictionary, context: sharedContext)
        newPin.name = locationNameStr

        do {
            //persist the new pin to core data
            try sharedContext.save()
            showPinOnMap(newPin)
        } catch let error as NSError {
            print("error saving the new pin in context")
        }
    }

    // use CLGeocoder to resolve the location name as title of the annotation
    CLGeocoder().reverseGeocodeLocation(CLLocation(latitude: newCoordinate.latitude, longitude: newCoordinate.longitude), completionHandler: {(placemarks, error) -> Void in

        if error …
Run Code Online (Sandbox Code Playgroud)

asynchronous ios deferred clgeocoder swift

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