小编Dav*_*zov的帖子

F#分割功能

我正在构建一个合并排序函数,我的split方法给了我一个值限制错误.我正在使用2个累积参数,这两个列表是由拆分产生的,我最后打包成一个元组用于返回.但是我得到了一个值限制错误,我无法弄清楚问题是什么.有没有人有任何想法?

let split lst = 
    let a = []
    let b = []
    let ctr = 0
    let rec helper (lst,l1,l2,ctr) =
        match lst with
          | [] -> [] 
          | x::xs -> if ctr%2 = 0 then helper(xs, x::l1, l2, ctr+1)
                    else 
                    helper(xs, l1, x::l2, ctr+1)
    helper (lst, a, b, ctr)
    (a,b)
Run Code Online (Sandbox Code Playgroud)

任何输入都表示赞赏.

recursion f# split value-restriction

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

从iOS将多个图像上传到S3的有效方法

我在应用程序中将Amazon S3用作文件存储系统。我所有的item对象都有几个与之关联的图像,并且每个对象仅存储图像URL,以保持数据库的轻量化。因此,我需要一种有效的方法直接从iOS将多个图像上传到S3,并在成功完成后将它们的URL存储在我发送给服务器的对象中。我仔细研究了Amazon提供的SDK和示例应用程序,但是我遇到的唯一示例是单个图像上传,操作如下:

 func uploadData(data: NSData) {
    let expression = AWSS3TransferUtilityUploadExpression()
    expression.progressBlock = progressBlock

    let transferUtility = AWSS3TransferUtility.defaultS3TransferUtility()

    transferUtility.uploadData(
        data,
        bucket: S3BucketName,
        key: S3UploadKeyName,
        contentType: "text/plain",
        expression: expression,
        completionHander: completionHandler).continueWithBlock { (task) -> AnyObject! in
            if let error = task.error {
                NSLog("Error: %@",error.localizedDescription);
                self.statusLabel.text = "Failed"
            }
            if let exception = task.exception {
                NSLog("Exception: %@",exception.description);
                self.statusLabel.text = "Failed"
            }
            if let _ = task.result {
                self.statusLabel.text = "Generating Upload File"
                NSLog("Upload Starting!")
                // Do something with uploadTask.
            }

            return nil;
    } …
Run Code Online (Sandbox Code Playgroud)

amazon-s3 amazon-web-services ios

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

递归返回错误,Java

所以我定义了一个递归函数,它将x的值作为参数(如算术变量x,即"x + 3 = 5")并返回算术表达式的结果.表达式取自二进制表达式树,如下所示: 在此输入图像描述

你从根部开始,继续向下工作,直到你击中叶子,一旦你做到了,你就会回来.树上的表达式是:

x*((x + 2)+ cos(x-4)).

我的这个函数的代码如下:

     // Returns the value of the expression rooted at a given node
// when x has a certain value
double evaluate(double x) {
    if (this.isLeaf()) {
        //convert every instance of 'x' to the specified value
        if (this.value.equals("x")) {
            this.value = Double.toString(x);
        }
        //return the string-converted-to-double

        return Double.parseDouble(this.value);
    }
    //if-else statements to work as the arithmetic operations from the tree. Checks the given node and performs the required operation
    else …
Run Code Online (Sandbox Code Playgroud)

java recursion binary-tree return return-type

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

使用指针C写入文件/从文件读取

我编写了一个程序,将指针写入文件(fwrite)并从文件读取指针(fread)。但是,该程序似乎没有在文件中写入任何内容,也没有从文件中读取任何内容。它只是将指针的最终增量打印5次并退出。谁能在我的语法中发现似乎正在执行此操作的错误/错误?

#include <stdio.h>

int main() {
    FILE *fTest;
    int *testPtr;
    int x = 10;
    
    if ((fTest = fopen("test.c", "wb")) == NULL) {
        printf("Error!");
    }

    testPtr = &x;
    int i;
    for (i = 0; i < 5; i++) {
        fwrite(testPtr, sizeof(int), 1, fTest);
        *testPtr += 1;
    }
    
    for (i = 0; i < 5; i++) {
        fread(testPtr, sizeof(int), 1, fTest);
        printf("%d", *testPtr);
    }

    fclose(fTest);
}
Run Code Online (Sandbox Code Playgroud)

c pointers file fwrite fread

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

无法识别的选择器迅速

我已经仔细阅读了有关此主题的SO以前的帖子,并且我确保我的代码不包含相同的错误,但是当我尝试点击我的UIButton时,我不断收到错误"无法识别的选择器发送到实例".谁能弄明白问题是什么?我确保我的动作名称和签名都与我连接到按钮的功能相同.我尝试重新启动XCode,它仍然无法正常工作.任何输入都表示赞赏.

import UIKit
import MapKit

class MapViewController: UIViewController {

    var mapView: MKMapView!

    override func loadView() {

        //create an instance of the MkMapView class and set it as the view controllers view
        mapView = MKMapView ()
        view = mapView

        //create a set of segmented controls to the map interface to give the user some options regarding their map 
        let segmentedControls = UISegmentedControl(items: ["Satellite", "Standard", "Hybrid"])

        //set the color of the segemented controls and set which index they default to on launch …
Run Code Online (Sandbox Code Playgroud)

ios swift

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