小编Voj*_*vik的帖子

Swift协议扩展覆盖

我正在尝试Swift协议扩展,我发现这个令人困惑的行为.你能帮助我如何得到我想要的结果吗?

请参阅代码最后4行的注释.(如果需要,可以将其粘贴到XCode7游乐场).谢谢!!

//: Playground - noun: a place where people can play

import UIKit

protocol Color { }
extension Color {  var color : String { return "Default color" } }

protocol RedColor: Color { }
extension RedColor { var color : String { return "Red color" } }


protocol PrintColor {

     func getColor() -> String
}

extension PrintColor where Self: Color {

    func getColor() -> String {

        return color
    }
}


class A: Color, PrintColor { }
class B: …
Run Code Online (Sandbox Code Playgroud)

xcode swift swift2

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

SwiftUI 覆盖取消触摸

我有一个按钮,我想在它上面放一个半透明的渐变叠加。

Button(action: {
  print("Pressed")
}) {
  Text("Press me")
}
.overlay(
  LinearGradient(
    gradient: Gradient(colors: [.clear, Color.black.opacity(0.3)]),
    startPoint: .top,
    endPoint: .bottom
  ).disabled(true)
)
Run Code Online (Sandbox Code Playgroud)

即使渐变有disabled(true)它仍然吃触摸并且不会将它们转发到实际按钮。.allowsHitTesting(false)提供相同的结果。

知道有什么问题吗?

注意:我知道我可以将覆盖层放置到Text("Press me")但我不想要它。(这只是展示问题的示例代码)


编辑:此问题已在 Xcode 11.2 中解决?

swiftui

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

SwiftUI DragGesture 仅在一个方向

我希望 SwiftUI DragGesture 仅在手势处于特定方向(水平/垂直)时启动。是否可以?

swiftui

10
推荐指数
2
解决办法
2324
查看次数

EXC_BREAKPOINT UNKNOWN崩溃线"0"

我在Crashlytics报告中遇到了这个奇怪的崩溃,我不知道发生了什么.我甚至不知道行号"0"的含义.有任何想法吗?

在此输入图像描述

来自didSelect方法的代码:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

    switch indexPath.section {

    case 1:
        let vc = WTShowDetailVC()
        vc.show = bottomFeaturedShows[indexPath.row].show
        navigationController?.pushViewController(vc, animated: true)

    case 2:
        let vc = WTShowDetailVC()
        vc.show = lastWatchedShows[indexPath.row]
        navigationController?.pushViewController(vc, animated: true)

    case 3:
        let vc = WTTapperProfileUserVC()
        vc.tapper = popularTappers[indexPath.row]
        navigationController?.pushViewController(vc, animated: true)

    default:
        println("Something went wrong")
    }
}
Run Code Online (Sandbox Code Playgroud)

crash ios swift

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

来自 xcodebuild 的“Xcode 无法确定配置文件类型”错误

使用 构建时xcodebuild,它返回以下错误:

xcodebuild[39801:1441114]  DVTAssertions: Warning in /Library/Caches/com.apple.xbs/Sources/IDEFrameworks/IDEFrameworks-14490.122/IDEFoundation/Provisioning/IDEProfileQualification.m:509
Details:  Xcode could not determine type of profile "/Users/xxxx/Library/MobileDevice/Provisioning Profiles/88a31133-a95d-4ae2-b516-f86dffe2f432.mobileprovision" (could be {(
)})
Object:   <IDEProfileQualification: 0x7fc8808118f0>
Method:   -_profileTypeQualifier
Thread:   <NSThread: 0x7fc8766457e0>{number = 6, name = (null)}
Please file a bug at https://bugreport.apple.com with this warning message and any useful information you can provide.
Run Code Online (Sandbox Code Playgroud)

xcode ios

4
推荐指数
1
解决办法
2441
查看次数

CLPlacemark在Swift中崩溃

我正在使用CLGeocoder反向地理定位并得到数组CLPlacemark.当我在美国境外使用GPS(即-27,127)然后访问时placemark.postalCode,应用程序崩溃:

"致命错误:在打开一个Optional值时意外地发现了nil".

看来,这placemark.postalCodenil没有邮政编码的地方.但是postalCodeSwift中的返回类型是String!:

var postalCode: String! { get } // zip code, eg. 95014

所以我甚至无法测试nil,因为崩溃是由吸气剂引起的postalCode.

任何想法如何防止这种崩溃?谢谢!

xcode ios clgeocoder swift clplacemark

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

标签 统计

ios ×3

swift ×3

xcode ×3

swiftui ×2

clgeocoder ×1

clplacemark ×1

crash ×1

swift2 ×1