标签: swift4

如何将Swift 3内置的cocoapod更新为Swift 4

所以我已经下载了Xcode 9测试版,我的任务是将我们的一个内部pod从Swift 3更新到Swift 4.我已经克隆了repo,并打开它,可以查看所有项目文件和其他所有内容,但没有计划,我无法使用,Edit > Convert > Convert to current Swift syntax因为它是灰色的.

在主项目中,我使用了迁移工具,然后手动完成并添加了@objc以暴露Objective-C中引用的内容,但我似乎无法使用pod进行操作.

我只是想知道是否有人有任何更新pod到Swift 4的经验,如果是这样我怎么去做,因为网上的信息很少.

非常感谢,一如既往

尼尔

xcode cocoapods swift swift4

0
推荐指数
1
解决办法
2787
查看次数

使用Swift 4 Decodable将字符串JSON响应转换为布尔值

我正在重构一些我之前使用过第三方JSON解析器的项目,而且我遇到了一个愚蠢的网站,它将一个布尔值作为字符串返回.

这是JSON响应的相关片段:

{
    "delay": "false",
    /* a bunch of other keys*/
}
Run Code Online (Sandbox Code Playgroud)

我的Decoding结构如下所示:

struct MyJSONStruct: Decodable {
  let delay: Bool
  // the rest of the keys
}
Run Code Online (Sandbox Code Playgroud)

我如何将JSON响应中返回的字符串转换为Bool以匹配Swift 4中的结构?虽然这篇文章很有帮助,但我无法弄清楚如何将字符串响应转换为布尔值.

json ios swift swift4 decodable

0
推荐指数
1
解决办法
1801
查看次数

将Google方向JSON字符串网址转换为网址

let stringOFDirection: String = "https://maps.googleapis.com/maps/api/directions/json?origin=23.0723857839751,72.5160750795044&destination=23.057534,72.577191&waypoints=optimize:true|23.0557874,72.465833"

let directionsURL = URL(string: stringOFDirection)!
Run Code Online (Sandbox Code Playgroud)

问题是directionsURL是零

我知道解决方案但是,在这个URL不起作用

请帮我!

json ios google-maps-sdk-ios swift swift4

0
推荐指数
1
解决办法
163
查看次数

从'[AVCaptureDevice]'到'[AVCaptureDevice]'的条件转换总是成功的.黄色警告

我有这个代码,它正在抛出黄色警告.我无法弄清楚如何编码它,所以黄色警告消失了.转换自Swift-2 - > 3 - > 4后尝试清理我的代码.

   override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        //On iPad Mini this returns 760 x 1024 = correct
        //On the iPhone SE, this returns 320x568 = correct
        print("Width: \(screenWidth)")
        print("Height: \(screenHeight)")

        //=======================

        captureSession.sessionPreset = AVCaptureSession.Preset.high

        if #available(iOS 10.0, *) {
            if let devices = AVCaptureDevice.default(AVCaptureDevice.DeviceType.builtInWideAngleCamera, for: AVMediaType.video, position: .back) {

                print("Device name: \(devices.localizedName)")

            }
        } else {

         }

 if let devices = AVCaptureDevice.devices() …
Run Code Online (Sandbox Code Playgroud)

ios-camera swift4 ios11 xcode9.1

0
推荐指数
1
解决办法
586
查看次数

UIImagePickerController在没有NS照片库和相机描述的情况下工作

我正在使用UIImagePickerController,因为我正在创建一个应用程序,该应用程序允许通过照片库和照相机发布图像。我创建了一个基本的演示,其中包含一个UIImageView,UIButton和一些用于设置UIImagePickerController的代码。此外,我还在Xcode的plist部分中设置了(NSPhotoLibraryUsageDescription和NSCameraUsageDescription)。图像拾取功能可以很好地运行,但是当我运行模拟器时,没有询问我是否应该让该应用程序允许访问我的相机或照片库。然后,我尝试取消plist语句并再次运行。没有这些,应用程序应该崩溃,但不会崩溃。

import UIKit

class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {


@IBOutlet weak var imageView: UIImageView!


@IBAction func importImage(_ sender: UIButton) {

    let imagePickerController = UIImagePickerController()
    imagePickerController.delegate = self

    let actionSheet = UIAlertController(title: "Add Your Profile Picture", message: "Choose An Option", preferredStyle: . actionSheet)

    actionSheet.addAction(UIAlertAction(title: "Camera", style: .default, handler: { (action:UIAlertAction) in
        if UIImagePickerController.isSourceTypeAvailable(.camera) {
            imagePickerController.sourceType = .camera
            self.present(imagePickerController, animated: true, completion: nil)
        }
        else {
            print("Camera not Available")
        }
    }))

    actionSheet.addAction(UIAlertAction(title: "Camera Roll", style: .default, handler:{ (action:UIAlertAction) in imagePickerController.sourceType = .photoLibrary …
Run Code Online (Sandbox Code Playgroud)

uiimagepickercontroller ios xcode8 swift4

0
推荐指数
1
解决办法
436
查看次数

使用分段控制更改视图

我需要使用分段控件来更改视图.在以下示例中,我将两个视图容器放在同一位置:

在此输入图像描述

第二个容器是隐藏的,每次我使用分段控件时我都会通过代码显示它.(虽然它也没有显示出来.)

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var container1: UIView!
    @IBOutlet weak var container2: UIView!

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }

    @IBAction func showComponent(_ sender: Any) {
        if (sender as AnyObject).selectedSegmentIndex == 0 {
            UIView.animate(withDuration: 0.5, animations: {
                self.container1.alpha = 1
                self.container2.alpha = 0
            })
        } else {
            UIView.animate(withDuration: 0.5, animations: {
                self.container1.alpha = 0
                self.container2.alpha = 1
            })
        }
    }

}
Run Code Online (Sandbox Code Playgroud)

你知道其他任何方法吗?

有没有办法自定义SegmentedControl,好像它是一个TAB?

ios swift swift4 ios11 xcode9

0
推荐指数
1
解决办法
4583
查看次数

密码重置Swift 4 Firebase

大家好,我正在使用Swift 4制作注册表并使用Firebase。

我一直在重设密码。每当我单击“忘记密码”按钮时,我都会得到一个带有textField的弹出窗口以填写我的电子邮件地址。但是当我点击时,什么也没有发生。在下面发布代码,如果有人有什么想法可能有什么问题

@IBAction func forgotPasswordTapped(_ sender: Any) {
    let forgotPasswordAlert = UIAlertController(title: "Forgot password?", message: "Enter email address", preferredStyle: .alert)
    forgotPasswordAlert.addTextField { (textField) in
        textField.placeholder = "Enter email address"
    }
    forgotPasswordAlert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
    forgotPasswordAlert.addAction(UIAlertAction(title: "Reset Password", style: .default, handler: { (action) in
        let resetEmail = forgotPasswordAlert.textFields?.first?.text
        Auth.auth().sendPasswordReset(withEmail: resetEmail!, completion: { (error) in
            if error != nil{
                let resetFailedAlert = UIAlertController(title: "Reset Failed", message: "Error: \(String(describing: error?.localizedDescription))", preferredStyle: .alert)
                resetFailedAlert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
                self.present(resetFailedAlert, animated: …
Run Code Online (Sandbox Code Playgroud)

firebase swift firebase-authentication swift4

0
推荐指数
1
解决办法
2580
查看次数

字典因应用程序崩溃而获得零值.在展开可选值时意外地发现了nil

我有一个名为messageDict的属性,有时它会因为该应用程序崩溃而获得nil值.有人可以建议我如何妥善处理它.

 var messageDict : [String : NSArray]?

if let messageDict = messageDict {
    let messageArray = messageDict[outBoxId]! as! [MCOIMAPMessage] // crash indicates here
}
Run Code Online (Sandbox Code Playgroud)

如果数据可用,我将存储在数据下面.有时它会是零

Message-ID: CABQG1ZJT0a7=NExme6VWA6iRpe6Du5LViuA9kZf-QbqOyX1RfQ@mail.gmail.com

References: [dca79b0a-ea55-a4f6-aef3-9097559148f5@peoplelogic.in,CABQG1ZKpat9nGSOjs-Q341bmn0vkiVH+CdFpu2JgkC92KO_K=Q@mail.gmail.com]

In-Reply-To: [CABQG1ZKpat9nGSOjs-Q341bmn0vkiVH+CdFpu2JgkC92KO_K=Q@mail.gmail.com]
Run Code Online (Sandbox Code Playgroud)

xcode ios swift swift3 swift4

0
推荐指数
1
解决办法
103
查看次数

Chameleon Framework与Swift 4不兼容吗?

看来Chameleon Framework与Swift 4不兼容。成功安装“ ChameleonFrame / Swift” pod之后,出现了大约30个构建时错误。我继续并修复了每个错误,并使其能够正常工作。生成的ChameleonShorthand.swift文件发布在下面。您可以将其复制并粘贴到您的相应文件中。如果有人有更好的解决方案,请告诉我。

import UIKit

// MARK: - UIColor Methods Shorthand

/**
Creates and returns a complementary flat color object 180 degrees away in the HSB colorspace from the specified color.

- parameter color: The color whose complementary color is being requested.

- returns: A flat UIColor object in the HSB colorspace.
*/
public func ComplementaryFlatColorOf(color: UIColor) -> UIColor {
    return UIColor(complementaryFlatColorOf: color)
}

/**
 Returns a randomly generated flat color object with an alpha value …
Run Code Online (Sandbox Code Playgroud)

xcode frameworks ios swift4

0
推荐指数
1
解决办法
2012
查看次数

如何使用swift导入和导出VCard文件

我是swift的新手.我在从iPhone导出联系人时遇到问题,并将其转换为.Vcf文件,用于将文件上传到Web服务器.此外,我想从Web服务器导入.Vcf文件并转换为iPhone联系人的模式.有谁能帮助我达到预期的效果?

xcode vcf-vcard contacts ios swift4

0
推荐指数
1
解决办法
611
查看次数