相关疑难解决方法(0)

1511
推荐指数
11
解决办法
72万
查看次数

如何从Swift调用Objective-C代码

在Apple的新Swift语言中,如何调用Objective-C代码?

Apple提到它们可以在一个应用程序中共存,但这是否意味着可以在技术上重用Objective-C中的旧类,同时在Swift中构建新类?

推理

Objective-C是一种独立于平台的语言,而Swift则依赖于平台.因此,在Swift中编写非平台相关代码(业务逻辑库)并不明智.但是,在其中编写与平台相关的代码(例如,与接口相关)将非常好.不是说这是一个好主意,但它肯定是一种兴趣.

objective-c swift

936
推荐指数
13
解决办法
27万
查看次数

在Swift框架中导入CommonCrypto

如何CommonCrypto在iOS的Swift框架中导入?

我理解如何CommonCrypto在Swift应用程序中使用:您添加#import <CommonCrypto/CommonCrypto.h>到桥接标头.但是,Swift框架不支持桥接头.该文件说:

您可以导入具有纯Objective-C代码库,纯Swift代码库或混合语言代码库的外部框架.无论框架是用单一语言编写还是包含来自两种语言的文件,导入外部框架的过程都是相同的.导入外部框架时,请确保将要导入的框架的"定义模块"构建设置设置为"是".

您可以使用以下语法将框架导入到不同目标中的任何Swift文件中:

import FrameworkName
Run Code Online (Sandbox Code Playgroud)

不幸的是,导入CommonCrypto不起作用.也没有添加#import <CommonCrypto/CommonCrypto.h>到伞头.

ios commoncrypto swift

181
推荐指数
8
解决办法
10万
查看次数

在命令行应用程序中从键盘输入

我正在尝试为新的Apple编程语言Swift获取命令行应用程序的键盘输入.

我扫描文档无济于事.

import Foundation

println("What is your name?")
???
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

macos cocoa command-line swift

90
推荐指数
6
解决办法
10万
查看次数

如何从UnsafeMutableRawPointer中获取字节?

如何通过C API(Core Audio等)将UnsafeMutableRawPointer(Swift 3中的新增内容)指向的内存访问字节(或Int16,浮点数等)移交给Swift函数

unsafe-pointers swift

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

无法从iOS访问https Web服务

我正在尝试访问https协议上提供的Web服务.最初我收到以下错误:

NSURLSession/NSURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9802)errorAn发生SSL错误,无法建立与服务器的安全连接.

我通过在info.plist中添加以下内容来修复它:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
    <key>NSExceptionDomains</key>
    <dict>
        <key>xx.xx.xxx.xxx</key>
        <dict>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
            <true/>
        </dict>
    </dict>
</dict>
Run Code Online (Sandbox Code Playgroud)

但是现在我在connectionDidFinishLoading委托方法中得到以下html作为响应:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

我正在使用以下来与服务器建立信任:

func connection(connection: NSURLConnection, canAuthenticateAgainstProtectionSpace protectionSpace: NSURLProtectionSpace) -> Bool{
    return true
}
func connection(connection: NSURLConnection, willSendRequestForAuthenticationChallenge challenge: NSURLAuthenticationChallenge){
    print("willSendRequestForAuthenticationChallenge")

    let protectionSpace:NSURLProtectionSpace = challenge.protectionSpace
    let sender: NSURLAuthenticationChallengeSender? = challenge.sender

    if(protectionSpace.authenticationMethod == …
Run Code Online (Sandbox Code Playgroud)

https ios swift tls1.2

15
推荐指数
1
解决办法
3918
查看次数

如何从Swift调用汇编函数

在xcode 8.0中,我有一个s文件,其中包含我编写的arm程序集代码块.我想调用这个asm函数并从我的Swift代码传递一个指针.我该怎么做呢?

以下是我在objective-c中做同样事情的方式:

void my_asm_function(int *myptr);   //this is prototype in my h-file

my_asm_function(&myIntVar);  // this is how i call the function from my obj-c code
Run Code Online (Sandbox Code Playgroud)

assembly function swift

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

swift 是否原生支持 C?

Objective C 可以本地编译 C。Objective C 是在 C 之上构建的。 swift 可以这样做吗?如果不是,有什么区别。

ios swift

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