首页 \ 问答 \ Swift:gettimeofday和Unsafe Pointers(Swift: gettimeofday and Unsafe Pointers)

Swift:gettimeofday和Unsafe Pointers(Swift: gettimeofday and Unsafe Pointers)

Swift中的代码

...
var time:timeval?
gettimeofday(UnsafePointer<timeval>, UnsafePointer<()>) // this is the method expansion before filling in any data
...

Objective C中的代码

...
struct timeval time;
gettimeofday(&time, NULL);
...

我一直在试图找到有关UnsafePointer和传递NULL的替代方法的更多信息,但是我可能会咆哮错误的树。

如果有人知道如何让Swift中的平等代码工作,那会很好。 如果有什么好的解释,它会更好!


The code in Swift

...
var time:timeval?
gettimeofday(UnsafePointer<timeval>, UnsafePointer<()>) // this is the method expansion before filling in any data
...

The code in Objective C

...
struct timeval time;
gettimeofday(&time, NULL);
...

I have been trying to find more information on UnsafePointer and alternatives to passing NULL, but I may be barking up the wrong tree.

If anyone knows how to get the equivilant code working in Swift, that would be great. If there is a good explanation of what's going on with it that would be even better!


原文:https://stackoverflow.com/questions/24655213
更新时间:2023-05-31 20:05

最满意答案

我解决了这个问题(感谢大家的提示)。 这适用于任何可能遇到类似问题的人。

我改变了我的Create方法,如下所示:

// GET: /Products/Create
public ActionResult Create()
{
    var p = new AddNewProductViewModel();
    p.Categories = entities.ProductCategories.ToList();
    return View(p);
}

我的AddNewProductViewModel看起来像这样:

using AccessorizeForLess.Data;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Web;

namespace AccessorizeForLess.ViewModels
{
    public class AddNewProductViewModel
    {
        public string Name { get; set; }

        [DataType(DataType.MultilineText)]
        public string Description { get; set; }

        public decimal Price { get; set; }

        public string AltText { get; set; }

        public int Quantity { get; set; }

        public HttpPostedFileBase Image { get; set; }

        public int SelectedCategoryId {get;set;}
        public List<ProductCategory> Categories { get; set; }
        public ProductCategory Category { get; set; }
    }
}

在我看来:

<div class="form-group">
    @Html.LabelFor(model => model.SelectedCategoryId, "Category",new { @class = "control-label col-md-2" })
    <div class="col-md-10">
        @Html.DropDownListFor(model => model.SelectedCategoryId, new SelectList(Model.Categories, "CategoryId", "CategoryName"), "- Please Select -")
        @Html.ValidationMessageFor(model => model.SelectedCategoryId)
    </div>
</div>

感谢大家的帮助:)


I solved the issue (thanks to everyone for the tips). This is for anyone who may be having issues like I was.

I changed my Create method to look like so:

// GET: /Products/Create
public ActionResult Create()
{
    var p = new AddNewProductViewModel();
    p.Categories = entities.ProductCategories.ToList();
    return View(p);
}

My AddNewProductViewModel looks like so:

using AccessorizeForLess.Data;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Web;

namespace AccessorizeForLess.ViewModels
{
    public class AddNewProductViewModel
    {
        public string Name { get; set; }

        [DataType(DataType.MultilineText)]
        public string Description { get; set; }

        public decimal Price { get; set; }

        public string AltText { get; set; }

        public int Quantity { get; set; }

        public HttpPostedFileBase Image { get; set; }

        public int SelectedCategoryId {get;set;}
        public List<ProductCategory> Categories { get; set; }
        public ProductCategory Category { get; set; }
    }
}

The in my view:

<div class="form-group">
    @Html.LabelFor(model => model.SelectedCategoryId, "Category",new { @class = "control-label col-md-2" })
    <div class="col-md-10">
        @Html.DropDownListFor(model => model.SelectedCategoryId, new SelectList(Model.Categories, "CategoryId", "CategoryName"), "- Please Select -")
        @Html.ValidationMessageFor(model => model.SelectedCategoryId)
    </div>
</div>

Thanks for the help everyone :)

相关问答

更多
  • @{ List listItems= new List(); listItems.Add(new SelectListItem { Text = "Exemplo1", Value = "Exemplo1" }); listItems.Add(new SelectListItem { Text = "Exemplo2 ...
  • 实际上可以在没有AJAX的情况下完成它但仍然需要一些Javascript: 第一个和第二个下拉列表都应该具有预先渲染的所有可用选项。 对于第二个下拉列表中的每个选项,指定第一个下拉列表的值应该是可见的。 例如: 元素)中的列表项由任何IEnumerable提供,它由ViewModel提供,或者可选地通过ViewData提供,如下所示: 视图模型: public class CustomerViewModel { public String Title { get; set; } public IEnumerable ValidTitles { get; set; } } 控制器动作: [HttpG ...
  • check this im doing that just now see my code $("#Container").on("change", "select", function () { var url = '/Controller/Action/Get'; $.ajax({ url: url, cache: true, type: "POST", ...
  • 在重新阅读您的问题后,您的答案似乎比预期的更简单。 查看选择列表类http://msdn.microsoft.com/en-us/library/system.web.mvc.selectlist.aspx 你在控制器中使用的构造函数是错误的,它应该是: ViewBag.jobClientsList = new SelectList(job.JobClients.ToList(), "ClientNumber", "Client"); 您将selectList的文本值设置为“ClientNumber”,这 ...
  • 还有第四种方式,我认为这是最好的方法。 由于您只有一个对象(类型为IEnumerable ),您可以将其作为模型传递给视图(不需要中间ViewModel)。 就可能性而言,没有真正的区别。 区别在于您的第一个方法和我刚才描述的方法是强类型的,这意味着您获得了Intellisense和编译时验证,而您的第二个和第三个方法是弱类型的,并且您没有智能感知和没有编译时验证。 There's a fourth way, which I think is the best way to ...
  • ViewBag.ListOfUnits = new SelectList(db.Units.OrderBy(q => q.Name).ToList(), "Id", "Name"); 更新: 脱离我的头顶: // Select Ids to exclude from list IQueryable exclude = db.Dep ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。