小编Dáv*_*tor的帖子

使用Swift 3检查iOS中的API响应时间?

我知道测试API的响应时间基本上是由服务器或后端端完成的,但是因为我正在为一个应用程序工作,我还需要检查来自iOS End的api响应时间.

我怎样才能做到这一点 ?我读了几个链接,它说使用计时器启动和计时器结束,然后通过endTime - startTime找到响应时间, 但这似乎不方便.

我想使用Xcode(即使XCTest在那里).

这是我的API之一(我在ApiManager类的单独类中编写了所有Web服务使用方法):

LoginVC:

//Call Webservice
let apiManager      = ApiManager()
apiManager.delegate = self
apiManager.getUserInfoAPI()
Run Code Online (Sandbox Code Playgroud)

ApiManager:

func getUserInfoAPI()  {
    //Header
    let headers =       [
        "Accept"        : "application/json",
        "Content-Type"  : "application/json",
    ]

    //Call Web API using Alamofire library
    AlamoFireSharedManagerInit()
    Alamofire.request(HCConstants.URL, method: .post, parameters: nil, encoding: JSONEncoding.default, headers: headers).responseJSON {  response in

        do{
            //Checking For Error
            if let error = response.result.error {
                //Stop AcitivityIndicator
                self.hideHud()
                //Call failure delegate method
                //print(error)
                  self.delegate?.APIFailureResponse(HCConstants.EXCEPTION_MESSAGES.SERVICE_FAILURE)
                return
            } …
Run Code Online (Sandbox Code Playgroud)

performance response ios swift3

5
推荐指数
3
解决办法
4737
查看次数

WKRefreshBackgroundTask尝试访问文件时出错bktasksnapshot_(null)

在watchOS 4.0(Xcode 9.0 beta 6)中执行后台任务时,我收到类似于下面的错误消息.它们似乎没有引起任何问题,但我不确定.有没有人知道是什么导致这些错误被记录,如果有修复或方法来抑制它们?

2017年8月24日09:03:40.130009-0400 cfanow关注应用信息[6906:377766] [bg_app_refresh] - [WKRefreshBackgroundTask cleanupStorage] _block_invoke:213:错误试图到达文件:///用户/ justindomnitz /库/开发/ CoreSimulator /设备/ 264AA014-FD6C-426A-88DF-64E502393BAF /数据/容器/数据/ PluginKitPlugin/107681EE-B30E-49CD-9416-8F030D1CA0BF /库/ com.apple.watchkit/bktasksnapshot_(空):错误域= NSCocoaErrorDomain代码= 260"无法打开文件"bktasksnapshot_(null)",因为没有这样的文件." 的UserInfo = {NSURL =文件:///用户/ justindomnitz /库/开发商/ CoreSimulator /设备/ 264AA014-FD6C-426A-88DF-64E502393BAF /数据/容器/数据/ PluginKitPlugin/107681EE-B30E-49CD-9416-8F030D1CA0BF /库/ com.apple.watchkit/bktasksnapshot_(空),NSFilePath = /用户/ justindomnitz /库/开发商/ CoreSimulator /设备/ 264AA014-FD6C-426A-88DF-64E502393BAF /数据/容器/数据/ PluginKitPlugin/107681EE-B30E- 49CD-9416-8F030D1CA0BF /库/ com.apple.watchkit/bktasksnapshot_(空),NSUnderlyingError = 0x79f3f3c0 {错误域= NSPOSIXErrorDomain代码= 2 "没有这样的文件或目录"}}

swift watchkit watchos-4

5
推荐指数
1
解决办法
343
查看次数

Xcode 在抛出 fatalError 时崩溃

static func saveContext (context: NSManagedObjectContext = getContext()) {        
    if context.hasChanges {        
        do {
            try context.save()
        } catch let nserror as NSError {      
            fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

(我把它放在保存 CoreData 上下文上)

当我抛出 fatalError 时,Xcode 本身每次都会崩溃,我必须再次打开它。

也许有人知道如何解决它或什么?

xcode core-data swift

5
推荐指数
0
解决办法
358
查看次数

在文件夹引用模式下添加文件时,Xcode找不到头文件

我正在尝试使用文件夹引用模式将许多 Objective-C 文件添加到我的 Swift 项目中,这意味着当我将文件拖放到项目中时,我选择“创建文件夹引用”。

这是因为我所有的 obj-c 文件都使用#include "/folder/folder/folder/"example. 这些文件是用j2objc生成的项目生成的。

现在我的问题是当我想要#import或Xcode 中的#include某些.h文件myproject-Bridging-Header.h找不到头文件时。我用#import "/folder/folder/folder/"类似生成的文件,但没有机会。

$(PROJECT_DIR)/在构建设置 - 搜索标头路径中添加,但它确实需要完全像$(PROJECT_DIR)/folder/folder/folder/. 有什么方法可以设置主文件夹和 Xcode 查找子文件夹吗?或者我需要单独写每个路径?

objective-c swift j2objc

5
推荐指数
1
解决办法
3728
查看次数

如何检测 Apple Watch 屏幕截图事件/数字表冠 + 侧边按钮按下?

例如,当用户同时按下数字表冠和侧面按钮(又名截屏)时,本机锻炼应用程序和 Sportstracker 能够暂停锻炼。

我需要这样的东西,但我在文档或网上其他地方找不到任何有关它的信息。对于 iOS,有“notificationUIApplicationUserDidTakeScreenshot”,但这在 watchOS 上不起作用。

有人知道怎么做吗?它是公开可用的还是私有 API?是我看起来不够好吗?

screenshot ios swift watchkit

5
推荐指数
1
解决办法
770
查看次数

UIVideoEditorController委托方法被调用两次

我正在使用UIVideoEditorController,但是成功委托方法为我调用了两次。但是,所有传递的对象的所有指针都告诉它发送完全相同的数据。

let editor = UIVideoEditorController()
editor.videoMaximumDuration = 10.0
editor.videoQuality = .typeIFrame1280x720
editor.delegate = self
editor.videoPath = // some path goes here
self.present(editor, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)

然后,以下方法将“ here”打印两次。

func videoEditorController(_ editor: UIVideoEditorController, didSaveEditedVideoToPath editedVideoPath: String) {
    print("here")
    self.dismiss(animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)

ios uivideoeditorcontroller swift

5
推荐指数
2
解决办法
479
查看次数

Venmo 深度链接

我一直在研究如何使用 venmo 深度链接方案,并尝试根据用户的用户名打开用户的帐户。我在互联网上查找了所有内容,最接近的是这篇博客文章。博客文章中的人非常接近实现我想要的目标,但我仍然无法弄清楚。我尝试多次更改“venmo://users”,试图用用户名打开个人资料,但没有任何效果。我怎样才能做到这一点?

先感谢您

deep-linking venmo swift

5
推荐指数
1
解决办法
3040
查看次数

Swift 5:在“self.init”调用之前使用“self”

我正在尝试使用所需的便利的可失败初始化程序。这是我正在使用的代码:

public init(authState: OIDAuthState, config: [String: String], accessibility: CFString = kSecAttrAccessibleWhenUnlockedThisDeviceOnly) throws {
        self.authState = authState
        self.config = config
        self.accessibility = accessibility

        super.init()

        KeycloakAuth.configuration = config
    }

public required convenience init?(coder aDecoder: NSCoder) {
        try? self.init(authState:     aDecoder.decodeObject(forKey: "authState")     as! OIDAuthState,
                       config:        aDecoder.decodeObject(forKey: "config")        as! [String: String],
                       accessibility: aDecoder.decodeObject(forKey: "accessibility") as! CFString)
    }
Run Code Online (Sandbox Code Playgroud)

'self' used before 'self.init' call我在线路上收到错误public required...,并且线路上再次出现相同的错误try? self.init(...

我查看了 Stack Overflow 上的其他一些相关问题。即这些:

  1. iOS Swift 便利初始化器 self 在 self.init 调用之前使用
  2. 在自定义类上使用 NSCoding 时,在 self.init 调用之前使用“self”错误 …

initialization swift swift5

5
推荐指数
1
解决办法
4854
查看次数

致命错误:无法构建模块“达尔文”

我是蒸汽的新手,我刚刚安装在 MacOS 上,我在构建它时遇到以下错误。有谁知道如何修理它?我已经搜索过,但提到的大多数解决方案都是针对 iOS 而不是 MacOS。

While building module 'Darwin' imported from /Users/imac1/ROOT/Vapor/Hello/.build/checkouts/swift-nio/Sources/CNIOHTTPParser/include/c_nio_http_parser.h:35:
In file included from <module-includes>:357:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include/ncurses.h:141:
/opt/local/include/unctrl.h:60:63: error: unknown type name 'SCREEN'
NCURSES_EXPORT(NCURSES_CONST char *) NCURSES_SP_NAME(unctrl) (SCREEN*, chtype);
                                                              ^
/opt/local/include/unctrl.h:60:53: error: function cannot return function type 'char *(int *, chtype)' (aka 'char *(int *, unsigned int)')
NCURSES_EXPORT(NCURSES_CONST char *) NCURSES_SP_NAME(unctrl) (SCREEN*, chtype);
                                                    ^
/opt/local/include/unctrl.h:60:54: error: a parameter list without types is only allowed in a function definition
NCURSES_EXPORT(NCURSES_CONST char *) NCURSES_SP_NAME(unctrl) (SCREEN*, chtype); …
Run Code Online (Sandbox Code Playgroud)

macos swift vapor

5
推荐指数
1
解决办法
1017
查看次数

.xcstrings 目录中的换行符

我正在尝试向新 Xcode 15 字符串目录(又名 xcstrings)中的字符串添加换行符。我什么也没想,就在\n想要换行的地方添加了平常的内容。

但在我的 SwiftUI 视图中,我可以看到实际转义的内容\n,并且文本不会换行。因此,文本“lorem ipsum\ndolor”将作为“lorem ipsum\ndolor”呈现给用户。

如何在不使用目录中的多个独立字符串的情况下创建带有有意换行符的文本?

xcode localization xcode15 xcstrings

5
推荐指数
1
解决办法
651
查看次数