小编Les*_*nel的帖子

Swift 3可选的转义闭包参数

鉴于:

typealias Action = () -> ()

var action: Action = { }

func doStuff(stuff: String, completion: @escaping Action) {
    print(stuff)
    action = completion
    completion()
}

func doStuffAgain() {
    print("again")
    action()
}

doStuff(stuff: "do stuff") { 
    print("swift 3!")
}

doStuffAgain()
Run Code Online (Sandbox Code Playgroud)

有没有办法制作类型的completion参数(和action)Action?并保持@escaping

更改类型会出现以下错误:

error: @escaping attribute only applies to function types

删除@escaping属性,代码编译并运行,但似乎不正确,因为completion闭包正在逃避函数的范围.

closures function optional swift3

148
推荐指数
5
解决办法
5万
查看次数

自动属性合成不会合成协议中声明的属性 - 哪一个?

它很好,它告诉我有这样一个属性,我必须合成,但有什么办法,我可以弄清楚它不是通过文档?我正在实施UITextInput protocol,无法弄清楚缺少什么.

protocols objective-c ios synthesize

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

当值丢失时,Codable 结构中使用的可选属性包装器失败

我有一个structDouble被表示为属性StringJSON从后端的到来。

struct Test: Codable {
    @StringRepresentation
    var value: Double?
}
Run Code Online (Sandbox Code Playgroud)

init(from:)我创建了以下属性包装器,而不是实现,它利用LosslessStringConvertible来转换String

@propertyWrapper
struct StringRepresentation<T: LosslessStringConvertible> {
    private var value: T?

    var wrappedValue: T? {
        get {
            return value
        }
        set {
            value = newValue
        }
    }
}

extension StringRepresentation: Codable {
    init(from decoder: Decoder) throws {
        let container = try decoder.singleValueContainer()
        if container.decodeNil() {
            value = nil
        } else {
            let string = try container.decode(String.self)
            value = T(string) …
Run Code Online (Sandbox Code Playgroud)

swift

12
推荐指数
1
解决办法
1150
查看次数

应用补丁来修复Eclipse中的bug?

我在Eclipse中有一个错误.当单步执行代码时,当它转到另一个类时,编辑器失去焦点,我必须再次单击编辑器以继续使用键盘快捷键进行调试.

我发现这个线程描述了这个bug,还有一个修补它的补丁.有什么方法可以应用补丁吗?我猜它涉及到源代码.

eclipse ide

8
推荐指数
1
解决办法
2104
查看次数

ios模拟器 - 禁用FOREVER的慢动画?

我不小心每天约50次转动慢动画(我想这可能是因为我通过Synergy使用虚拟键盘)...如何禁用模拟器中的慢动画FOREVER?

ios-simulator

7
推荐指数
1
解决办法
2677
查看次数

如何配置Windows Azure WCF服务Web角色以使用netTcpBinding?

我在Windows Azure上托管了WCF服务,最近我将其合同更改为双工合同(以支持客户端上的进度条).我首先使用wsDualHttpBinding,它在我的本地机器上运行良好,但是一旦我部署它就像预期的那样无法工作.

我现在正在尝试配置服务以使用netTcpBinding,但我收到错误"指定的协议无效.目前不支持名为'Endpoint1'的绑定的协议'tcp'."

ServiceDefinition.csdef:

<Endpoints>
  <InputEndpoint name="AlertsEndpoint" protocol="tcp" port="3030" />
</Endpoints>
Run Code Online (Sandbox Code Playgroud)

Web.config文件:

 <services>      
      <service name="AlertsService.AlertsService" behaviorConfiguration="AlertsServiceBehavior">
        <endpoint address="" binding="netTcpBinding" bindingConfiguration="NetTcp" contract="AlertsService.IAlertsService" />
        <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="MexTcp" contract="IMetadataExchange" />
      </service>
    </services>  

<bindings>
      <netTcpBinding>
        <binding name="NetTcp" />
      </netTcpBinding>
      <mexTcpBinding>
        <binding name="MexTcp"/>
      </mexTcpBinding>
</bindings>      
Run Code Online (Sandbox Code Playgroud)

.net c# windows wcf azure

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

Metro UI Multibinding?

Metro UI中不支持多绑定吗?或者它还没有被添加?

<TextBlock>
  <TextBlock.Text>
    <MultiBinding StringFormat="{}{0},{1}">
      <Binding Path="FirstName" />
      <Binding Path="LastName" />
    </MultiBinding>                
  </TextBlock.Text>                
</TextBlock>
Run Code Online (Sandbox Code Playgroud)

multibinding microsoft-metro

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

显示 Eclipse 迷你进度条?

愚蠢的问题:如何在 Eclipse 中恢复微小的进度条?我设法把它从存在中拖出来......

在此输入图像描述

eclipse

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

无法在设备上安装Xcode Server bot生成的ipa

我已经在mac mini上安装了我的Xcode服务器.使用Itunes 从https://pandora.local/xcode/下载.ipa就可以了.

我尝试直接从safari手机安装它.它会安装证书,但是当我点击安装时会出现错误,说它无法连接到服务器.

在此输入图像描述 在此输入图像描述

xcode ios xcode-bots xcode-server

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

使用Functional Swift的Fibonacci项的和

我正在尝试学习函数Swift并开始从Project Euler做一些练习.

甚至Fibonacci数问题2 Fibonacci序列中的每个新项都是通过添加前两个项生成的.从1和2开始,前10个术语将是:

1,2,3,5,8,13,21,34,55,89 ......

通过考虑Fibonacci序列中的值不超过四百万的项,找到偶数项的总和.

根据WWDC高级Swift视频实现了一个memoized斐波那契函数:

func memoize<T:Hashable, U>( body: ((T)->U,T) -> U) -> (T)->U {
  var memo = [T:U]()
  var result: ((T)->U)!
  result = { x in
    if let q = memo[x] { return q }
    let r = body(result,x)
    memo[x] = r
    return r
  }
  return result
}

let fibonacci = memoize { (fibonacci:Int->Double,n:Int) in n < 2 ? Double(n) : fibonacci(n-1) + fibonacci(n-2) }
Run Code Online (Sandbox Code Playgroud)

并实现了一个符合Sequence协议的类

class FibonacciSequence: SequenceType {
  func generate() -> GeneratorOf<Double> …
Run Code Online (Sandbox Code Playgroud)

functional-programming swift

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