小编Nik*_*nov的帖子

在Swift 1.2中编码和解码枚举

我enum在我的Swift类中声明了一个变量.我需要使用编码和解码它NSCoder.对于我应该使用的这个说法有很多问题rawValue.Enum声明如下:

enum ConnectionType {
    case Digital, PWM
}
Run Code Online (Sandbox Code Playgroud)

但是在Swift 1.2中没有这样的初始化器.在Swift 1.2和Xcode 6.3中如何做到这一点?

nscoder ios swift

3
推荐指数
1
解决办法
885
查看次数

如何在 iOS 中使用 AWSMobileClient 获取 AWS Cognito 用户属性?

问题非常简单:我已使用 AWS Cognito 和 AWS Amplify 将用户身份验证添加到 iOS 应用程序。我已经成功实现了登录和注册,但是如何获取用户属性,例如电子邮件、全名或电话号码?

amazon-web-services ios amazon-cognito

3
推荐指数
1
解决办法
4939
查看次数

iOS - 从 UITableView 崩溃中删除行

我正在尝试通过以下方式从表视图和核心数据中删除行:

override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
    if (editingStyle == UITableViewCellEditingStyle.Delete) {
        managedObjectContext?.deleteObject(self.fetchedResultsController.objectAtIndexPath(indexPath) as! NSManagedObject)
        managedObjectContext?.save(nil)
        self.tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Fade)
        self.tableView.reloadData()
    }
}
Run Code Online (Sandbox Code Playgroud)

但是在self.tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Fade)我的应用程序上崩溃并出现以下错误:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0.  The number of rows contained in an existing section after the update (7) must be equal to the number of rows contained in that section before the update (7), plus or …
Run Code Online (Sandbox Code Playgroud)

uitableview ios swift

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

NSMutableURLRequest - 来自Swift Array的HTTPBody

我需要使用HTTPBody of Array向我的服务器发送一个post请求.这是我的参数数组:

params = [
            "message"  : [
                "alert" : "Find your iPhone",
                "sound" : "Binocular_Default.caf"
            ]
        ]
Run Code Online (Sandbox Code Playgroud)

现在我需要将NSMutableURLRequest's' 设置HTTPBody为此数组.我怎样才能做到这一点?

nsurlrequest ios swift

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

iOS SDK:转角半径显示不正确

这是我在Sketch中设计的屏幕:

在此处输入图片说明

有两个按钮。现在,我正在Xcode中设计这样的按钮,并以这种方式设置UIButton的角半径:

layer.cornerRadius = 30
clipsToBounds = true
Run Code Online (Sandbox Code Playgroud)

但是结果是我有些奇怪:

在此处输入图片说明

如果按钮的左侧和右侧,您会看到中间的某个角。我能做什么?

uibutton uiview ios swift

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

Nil Coalescing Operator Swift

我快速遇到了一个问题.在Objective-C中,我这样写:

return !item ? self.people.count : item.children.count
Run Code Online (Sandbox Code Playgroud)

因此,如果item为nil,则返回self.people.count,否则返回item.children.count.如何在Swift中编写这样的东西?

objective-c swift

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

Swift - AVAudioPlayer不起作用

我试图aiff通过以下方式在iOS应用程序中播放我的文件:

var sound = NSBundle.mainBundle().pathForResource("tropical_birds", ofType: "aiff")
var soundData = NSData(contentsOfFile: sound!)
let audioPlayer = AVAudioPlayer(data: soundData, error: nil)
audioPlayer.prepareToPlay()
audioPlayer.play()
Run Code Online (Sandbox Code Playgroud)

audio avaudioplayer ios swift

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

无法通过POST获取数据

在html文件中,我有以下部分代码:

<!-- Contact Form -->


<section>
        <form method="post" action="sendmail.php">
                <div class="row 50%">
                        <div class="6u">
                                <input type="text" name="name" id="contact-name" placeholder="Name" />
                        </div>
                        <div class="6u">
                                <input type="text" name="email" id="contact-email" placeholder="Email" />
                        </div>
                </div>
                <div class="row 50%">
                        <div class="12u">
                                <textarea name="message" id="contact-message" placeholder="Message" rows="4"></texta$
                        </div>
                </div>
                <div class="row">
                        <div class="12u">
                                <ul class="actions">
                                        <li><input type="submit" class="style1" value="Send" /></li>
                                        <li><input type="reset" class="style2" value="Reset" /></li>
                                </ul>
                        </div>
                </div>
        </form>
</section>
Run Code Online (Sandbox Code Playgroud)

在php文件sendmail.php中,我有:

<?php
    $address = $_POST['contact-email'];
    $body = $_POST['contact-message'];
    $name = $_POST['contact-name'];
    echo($address);
    echo($body);
    echo($name);
Run Code Online (Sandbox Code Playgroud)

?>

当我尝试运行此表单时,它不会执行任何操作.也许我做错了什么?

html php post

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

iOS NSDate()返回不正确的时间

我正在尝试使用Swift获取当前日期NSDate().当我创建断点并停止应用程序时,我可以看到设备的系统时间有3个小时的差异.应用程序在真正的iPhone上运行.如何解决这个问题?

我还在App Delegate中写了以下内容以确定:

NSTimeZone.setDefaultTimeZone(NSTimeZone(name: "Europe/Kiev")!)
Run Code Online (Sandbox Code Playgroud)

但它仍然无效.

nsdate ios swift

0
推荐指数
2
解决办法
5215
查看次数