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
最满意答案
我解决了这个问题(感谢大家的提示)。 这适用于任何可能遇到类似问题的人。
我改变了我的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: 第一个和第二个下拉列表都应该具有预先渲染的所有可用选项。 对于第二个下拉列表中的每个选项,指定第一个下拉列表的值应该是可见的。 例如:@if (ViewBag.UserName !=null && (ViewBag.UserName as IList
).Count >0) { ...我解决了这个问题(感谢大家的提示)。 这适用于任何可能遇到类似问题的人。 我改变了我的Create方法,如下所示: // GET: /Products/Create public ActionResult Create() { var p = new AddNewProductViewModel(); p.Categories = entities.ProductCategories.ToList(); return View(p); } 我的AddNewProductViewMo ...你可以尝试改变 ViewBag.UserListing = new SelectList(db.Users, "Id", "UserName", ticketVM.UserId); 至 ViewBag.UserId = new SelectList(db.Users, "Id", "UserName", ticketVM.UserId); 或改变 @Html.DropDownList("UserId", @ViewBag.UserListing, null); 至 @Html.DropDownList("U ...MVC DropDownList (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", ...使用MVC3.net中的复合键记录填充DropdownList?(Populate a DropdownList with composite key records in MVC3.net?)[2020-02-06]
在重新阅读您的问题后,您的答案似乎比预期的更简单。 查看选择列表类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 IQueryableexclude = db.Dep ... 相关文章
更多- 千锋首发Swift视频教程
- Swift入门视频教程-尚学堂视频教程
- 【转】Java's hashCode is not safe for distributed systems
- 学习di'z地址
- Prince Of Persia III - The Two Thrones 通关完成
- Hadoop的thrift server配置
- James wearing New jordans 2013
- 分布式助手Zookeeper(八) - 三劫散仙
- 分布式助手Zookeeper(六) - 三劫散仙
- Jordan 11 magic reversal
最新问答
更多- 获取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的基本操作命令。。。