首页 \ 问答 \ 将Int保存到核心数据的正确方法?(Correct method to save an Int into core data?)

将Int保存到核心数据的正确方法?(Correct method to save an Int into core data?)

我有一个具有Int16属性的实体。

在此处输入图像描述

我想保存var userRepsCount = Int() ,它由以下步进方法设置:

@IBAction func userRepsStepper(_ sender: UIStepper) {
    userExerciseRepsCounter.text = Int(sender.value).description
    self.userRepsCount = Int(sender.value)
}

我想将此添加到属性并使用userExercise.reps = userRepsCount来执行此操作,但是我收到错误

无法将“Int”类型的值指定为“Int16”类型

我的印象是Int16可以毫无问题地存储这样的int? 我在这里想念的是什么?


I have an entity with an Int16 attribute.

enter image description here

I want to save var userRepsCount = Int() which is set by the below stepper method:

@IBAction func userRepsStepper(_ sender: UIStepper) {
    userExerciseRepsCounter.text = Int(sender.value).description
    self.userRepsCount = Int(sender.value)
}

I want to add this to the attribute and am using userExercise.reps = userRepsCount to do so, however I get the error

Cannot assign value of type 'Int' to type 'Int16'

I was under the impression that Int16 could store int's such as this without issue? What am I missing here?


原文:https://stackoverflow.com/questions/40775980
更新时间:2019-12-03 09:45

最满意答案

尝试用Int64(userRepsCount)包装它,然后当你拉它时,在处理它之前用Int(value)包装它


Try wrapping it with Int64(userRepsCount), and then when you pull it, wrap it with Int(value) before you process it

2017-08-18

相关问答

更多

如何使用nscala-time生成随机DateTimes(How to generate random DateTimes with nscala-time)

只需绕过nscala-time就可以使用new关键字: val startTimestamp = new DateTime(Random.nextLong(1000)) val endTimestamp = new DateTime(Random.nextLong(1000) + 1000) 返回类型是相同的。 Just bypass nscala-time on this one and use the new keyword: val startTimestamp = new DateTi

更改JMXReporter的默认行为(Change the default behavior of JMXReporter)

您可以更改通过发布度量标准的ObjectName,但MBean属性名称已硬编码到JmxReporter中。 JmxReporter $ JmxGauge也是私有的,因此,改变它的唯一方法是实现自己的JmxReporter。 You can change the ObjectName the metric is published through, but the MBean attribute name is hard-coded into the JmxReporter. JmxReporte

将网页的HTML加载到字符串(Loading a web page's HTML to a string)

我更喜欢使用HttpBodyHandler进行解析: HttpClient client = new HttpClient(); client.getUrl(Uri.parse("http://www.example.com/")) .then((HttpClientRequest response) => response.close()) .then(HttpBodyHandler.processResponse) .then((HttpClientResponseBod

在HTTP调用OptimusHTTP上加载对话框(Loading Dialog on HTTP call OptimusHTTP)

@navotera:您可以在发出请求之前显示ProgressDialogue,当请求完成时,在侦听器下只需关闭进度对话框。 即 ... @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ... ... // Initialize the progressdialog

选择列表,显示不在模型中的项目(Select list showing items not in model)

类似于@Oren的回答,但我认为您需要将其声明为属性并通过@each观看用户的内容 users: function(){ return this.get('model.users').filter(function(user){ return !users.contains(user); }); }.property('model.users.@each') Similar to @Oren's answer, but I think you will need to decl

将所有输出放在JavaScript中的while循环中的特定文本框中(Putting all the output in a specific textbox in a while loop in JavaScript)

你可以这样做: 给答案输入一个id: <input id="answerTextBox" type="text" name="ans" disabled> while循环后填充answer文本框: while (x>y) { document.getElementById("answerTextBox").value += ("" + x); x=x+1; } 这将把x和y放在你的答案文本框中。 UPDATE ****** <html> <body> <script type="tex

如何在AsyncTask或Fragment中处理Null?(How to handle Null in AsyncTask or Fragment?)

在onPost()方法中写一个文档检查 if (document!=null){ Elements elementsId = document.select("id"); Elements elementsCheckin = document.select("checkin"); Elements elementsCheckout = document.select("checkout"); Elements ele

我无法运行Java程序(I can't run a Java program)

您的通话中有拼写错误。 更改 System.out.printIn("hello youtube"); // capital 'I' 至 System.out.println("hello youtube"); // lowercase 'l' 正如已经提到的,在Java中,文件中的public类必须与文件名匹配。 You have a typo in your call. Change System.out.printIn("hello youtube"); // capital '

相关文章

更多

最新问答

更多
  • 根据Woocommerce中的自定义字段计算自定义购物车商品价格(Custom cart item price calculation based on dimentions custom fields in Woocommerce)
  • 分开foreach项目并单独打印(Separate foreach items and print them individually)
  • 写模式管道是否同步?(Is write mode pipe synchronous?)
  • 发现可用的Windows Phone强调色和本地化名称(Discover available Windows Phone accent colors and localized names)
  • 使用多线程和WPF更新集合(Update Collection with multithreading and WPF)
  • 如何在字符串的情况下使用同步?(How should the synchronization be used in case of strings?)
  • 打印唯一的行,比较不超过N个字符(Print unique lines, compare no more than N characters)
  • Javascript / jQuery - 如何调用switch case从另一个函数执行(Javascript/jQuery - how to call a switch case to execute from another function)
  • Hbase超时错误不断发生(Hbase timeout errors keep occuring)
  • 如何在Delphi中更改TabControl中活动TAB的颜色(How to change the color of active TAB in a TabControl, in Delphi)
  • 正则表达式:在sublime文本中替换一些PHP代码(Regex: replace some pieces of php code in sublime text)
  • 在带有Scene2D的LibGDX中,如何在按下按钮时连续向右走?(In LibGDX with Scene2D, how can I continuously walk to the right when a button is pressed?)
  • 累加器如何在Haskell中工作?(How do accumulators work in Haskell?)
  • 使用开关检查市场和前缀与正确的货币符号(using switch to check market and prefix with correct currency symbol)
  • 在哪里分配一次使用类?(Where to allocate one time use class?)
  • 如何从两个DateTime / NaiveDateTime获取持续时间?(How do I get Duration from two DateTime / NaiveDateTime?)
  • 解析TimeSpan大于24小时?(Parse a TimeSpan greater than 24 hours? [duplicate])
  • 如何在球拍中本地更改阅读规则?(How to locally change reading rules in racket?)
  • 数据库应该由DI注入时的模拟存储(通过构造函数)(Mock storage when database should be injected by DI (through constructor))
  • 使用maven集成2个eclipse项目(Integrate 2 eclipse projects using maven)
  • 角度ng-repeat不检测变化(Angular ng-repeat not detecting changes)
  • Xaml组件在Silverlight + XNA应用程序的多个页面中可见(Xaml component visible in multiple pages in Silverlight+XNA applications)
  • 如何将`var`变量等同于另一个查询(How to equate `var` variable to another query)
  • 如何设计hyperledger链代码以适合您的业务?(how to design your chaincode of hyperledger to fit for your business?)
  • PHP readfile错误(PHP readfile error)
  • 在Date之后排序列表然后是时间(Sorting list after Date then time)
  • Android内部版本号(Android build number)
  • 在没有预设退出条件的情况下停止无限循环(stopping an infinite loop with no preset exit condition)
  • Phonegap应用程序全屏通过html页面中的按钮(Phonegap Application fullscreen through a button in html page)
  • PAA是否适合在门户网站中自动执行wcm库部署和设置?(Is PAA a good candidate for automating wcm library deployment and setup in portal?)