问题标签 [swift4.1]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
0 回答
546 浏览

ios - 在 swift 4.1 中添加子视图自身导致崩溃

我有一个自定义视图,其 init 方法如下。这曾经在 Xcode 9.1 和 swift 4 中正常工作。今天我更新到 Xcode 9.3 并将项目基础设置为 swift 4.1,它开始在这个 init 方法中崩溃。

崩溃堆栈跟踪

0 投票
0 回答
75 浏览

swift - 拐角半径延迟

我目前正在通过故事板用户定义的运行时属性窗口设置 UIView 的角半径。

在此处输入图像描述

当我启动应用程序时,有 2-3 秒的延迟,然后我才看到角半径被应用。

这是一个新项目,所以只有这个 UIView,什么都没有。

知道为什么我会看到这种延迟吗?我已将视图固定在超级视图的前导、尾随和底部。然后我将高度设置为常数。

0 投票
1 回答
151 浏览

swift4 - NSRegularExpression.replacementString doesn't track changes in string length

I'm trying to write some code where I iterate over regex matches in a string and run an operation on the match, replacing it with the result of the operation. I'm running into problems though, where inside my replacementString() override the supplied range of the 2nd and subsequent matches don't match the locations in the source string if the previous replacement strings aren't precisely the same length as their original match substring.

I've constructed a simple example to demonstrate the problem.

The output I expect from this is:

But, the output I get is this:

The final substitution gets put in the right place, but since I'm trying to run an operation on the matched text, I need the right substring to show up in my magic() method.

I can try to track the difference in the matches and the resulting replacement string and modify each range by the +/- ... or brute force the whole thing and just iterate over matches() until there aren't any left, but I'm wondering if there's a more elegant way to make this work.

0 投票
2 回答
86 浏览

swift4 - Pass a class type for use inside a method

In order to reduce cut-and-paste code in this app, I'm trying to pass class names around in order to tell a method which way it should process some data. I have something like the following:

#xA;

Passing withClass cls: AnyClass the parser pushed me to change let x = cls() to let x = cls.init(). But I've got an Expected member name or constructor call after type name error for the last two lines. The recommended fixes both cause other problems.

The first suggestion, adding the () constructor after the class name, causes new errors on those lines: Cannot convert value of type 'OneClass' to expected argument type 'AnyClass' (aka 'AnyObject.Type')

Taking the second suggestion and changing them to OneClass.self and TwoClass.self gets rid of the parser errors, but when I execute the code it just runs forever.. never erroring out, and never completing.

I found a recommendation elsewhere that suggests I should change the Thing.doStuff() parameters to expect MyClass instead of AnyClass, but that causes another set of new problems.

First, the parser starts complaining about the cls.init() call, and the series of fixes it suggests eventually lead to something that makes no sense: let x = cls.type(of:;; init)(). The parser ends up in a suggestion loop where it keeps adding more semi-colons in the middle of the statement.

Second, I'm back to type mismatch errors on the calls to doStuff() in the last two lines: Cannot convert value of type 'OneClass.Type' to expected argument type 'MyClass'.

There's obviously something I'm not getting here about passing types as arguments, but none of the googling I've done has landed me on something that explains the problems I'm seeing.

0 投票
1 回答
30 浏览

ios - 添加子视图时无法修改视图元素

背景:

我有 4 个 .XIB 文件,它们以编程方式初始化为要通过 self.view.addSubview(UIView) 方法调用到屏幕的子视图。

当我调用self.view.addSubview(degreeAuditBachelorsViewResults!)时,视图会正确显示此 XIB UIView 并相应地填充所有文本框和显示元素。

问题: 当我调用self.view.addSubview(degreeAuditAssociatesViewResults!)(第二个代码块)时,视图会显示此 XIB UIView,但不会填充文本框中的任何数据。

奇怪的是 当我删除代码并且从不初始化第四个 UIView(第四个代码块)(degreeAuditBachelorsViewResults)时,degreeAuditAssociateResults UIView 加载没有问题。

当我在代码块中移动时,(块 2)或(块 4)都没有显示,所有文本元素都填充了信息。我感觉它与 addSubview(UIView) 方法有关,不接受任何信息。

请帮助,我已经用完了选项。

0 投票
1 回答
345 浏览

swift4.1 - Swift 4.1:字典中的数组未更新

这种奇怪的行为让我感到困惑。我打算创建一个带有单个数组字段的字典。然后在这个数组中,附加了两个额外的子字典。这是代码,

调试器输出

在此处输入图像描述

从调试器输出中可以看到,var 数组已成功更新(附加了 2 个子字典)。但dictionary["array"]仍然有 0 值。

看起来 ( dictionary["array"]) 和 ( array) 是两个独立的对象

0 投票
1 回答
798 浏览

arrays - 用于惰性集合的 Swift 4.1 compactMap

在 Swift 4.1 之前,我曾经从集合flatMap中删除nil值。现在此方法已弃用,我需要将其替换为compactMap. 有时我使用flatMap惰性集合来优化我的代码,如下所示:

如果我使用compactMap而不是,它会产生相同的效果flatMap吗?在该方法的文档中,lazy我找到了对mapfilter仅引用。

0 投票
0 回答
334 浏览

ios - 使用 Facebook 应用程序登录时崩溃。(Safari 或 Web 工作)。斯威夫特 4.1

升级到 Swift 4.1 后我遇到了奇怪的崩溃

每次用户使用 NATIVE 选项使用 Facebook 应用程序登录我的应用程序时(如果它安装在设备上,这将打开您的 Facebook 应用程序本身)。我收到以下异常

屏幕看起来像这样仅供参考:

我的应用不是 blubshare,我把它从互联网上拉下来了

Crashlytics 给我的所有内容如下

AppDelegate.swift line 0 @objc AppDelegate.application(UIApplication, open : URL, sourceApplication : String?, annotation : Any) -> Bool 2 UIKit
__58-[UIApplication _applicationOpenURLAction:payload:origin:]_block_invoke + 880

我已经能够在我的设备上重现,并且本地崩溃日志同样没有帮助。崩溃发生在我的 AppDelegate 文件的第一行,在可理解的代码中没有任何东西可以回溯。

这显然是违规行。

我已经尝试启用 Zombie 对象,因为 EXC_BAD_ACCESS 通常意味着某些东西被解除分配,以收集一些没有运气的数据。

奇怪的是,如果我执行以下操作:

不会发生崩溃。这让我相信,当使用 .native 选项(如果您安装了 facebook,则为默认选项)时,应用程序切换会以某种方式导致崩溃。

使用 .web 是一种临时解决方法,但我真的很想知道为什么这会导致崩溃的根本原因。FBSDKLoginKit 对我来说是 4.32.0 版。

任何想法或帮助表示赞赏。

0 投票
1 回答
283 浏览

ios - 如何从“MGLConstantStyleValue”迁移到“NSExpression”

我正在尝试从迁移mapbox-sdk-3.7mapbox-sdk-4.0.

我不明白如何将此语法转换为MGLConstantStyleValueto NSExpression

0 投票
2 回答
74 浏览

ios - 如何在 Swift 4 中提取特定数组

我想通过它的键来获取数组值。

我在 looping 中用下面的代码设置了数组。

现在我得到下面的数组。这是我的数组。

我通过使用调用值

但它'显示错误。我如何通过索引或 smth 调用值。请帮我。