我Dictionary<String,AnyObject>在Swift iOS应用程序中使用类型的params列表来保存一些最终将传递给webservice的参数.如果我要将Bool保存到此字典然后打印它,它将显示为"Optional(1)",因此它将被转换为int.我不能发送一个int,需要这个"真实".示例代码如下.
var params = Dictionary<String,AnyObject>()
params["tester"] = true
println(params["tester"])
Run Code Online (Sandbox Code Playgroud)
如何将其保存为实际的真/假值而不是整数?
注意事项
这与AFNetworking一起使用,因此参数必须是形式 AnyObject!
AFNetworking结构如下:
manager.GET(<#URLString: String!#>, parameters: <#AnyObject!#>, success: <#((AFHTTPRequestOperation!, AnyObject!) -> Void)!##(AFHTTPRequestOperation!, AnyObject!) -> Void#>, failure: <#((AFHTTPRequestOperation!, NSError!) -> Void)!##(AFHTTPRequestOperation!, NSError!) -> Void#>)
Run Code Online (Sandbox Code Playgroud)
'parameters'参数是我在Dictionary<String,AnyObject>as中传递的.
我正在尝试使用AVFoundation使用以下代码读取条形码,但我不断收到以下错误.帮助为什么会非常感激.提前致谢!
//Create camera view
session = AVCaptureSession()
var layer = self.cameraView.layer
vidLayer = AVCaptureVideoPreviewLayer.layerWithSession(session) as AVCaptureVideoPreviewLayer
vidLayer.frame = self.cameraView.bounds
vidLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
var device = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)
var error:NSError? = nil
var input:AVCaptureDeviceInput? = AVCaptureDeviceInput.deviceInputWithDevice(device, error: &error) as? AVCaptureDeviceInput
var output = AVCaptureMetadataOutput();
session.addOutput(output)
output.setMetadataObjectsDelegate(self, queue: dispatch_get_main_queue())
output.metadataObjectTypes = [AVMetadataObjectTypeUPCECode, AVMetadataObjectTypeCode39Code, AVMetadataObjectTypeCode39Mod43Code, AVMetadataObjectTypeCode93Code, AVMetadataObjectTypeEAN13Code, AVMetadataObjectTypeEAN8Code, AVMetadataObjectTypeCode128Code, AVMetadataObjectTypePDF417Code, AVMetadataObjectTypeQRCode, AVMetadataObjectTypeAztecCode]
if(input != nil){
println("ADDED")
session.addInput(input)
}
layer.addSublayer(vidLayer)
session.startRunning()
2014-10-07 15:25:09.279 WegmannMobile[457:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[AVCaptureMetadataOutput …Run Code Online (Sandbox Code Playgroud) 我有一个迁移,在下面,我用index:true创建索引.但是,该索引的名称太长,所以我试图自己命名.但是,这似乎没有运行.我得到相同的"名字太长"错误.有没有办法用index:true命名这样的索引?如果没有,我如何用add_index命名呢?
class CreateVehicleProductApplicationNotes < ActiveRecord::Migration
def change
create_table :vehicle_product_application_notes do |t|
t.references :product_id, index: true
t.references :product_application_id, index: true, :name "my_index"
t.references :note_id, index: true
t.timestamps
end
end
end
Run Code Online (Sandbox Code Playgroud) 我试图获得键盘的UIAnimationCurve,如果它存在的话.我使用的代码如下:
if let kbCurve = userInfo[UIKeyboardAnimationCurveUserInfoKey] as? Int{
animateCurve = UIViewAnimationCurve.
}
Run Code Online (Sandbox Code Playgroud)
但是,作为UIViewAnimationCurve的animateCurve无法从Int转换.我如何以这种方式获得曲线?
如果我将它们视为数字,而不是UIViewAnimationCurve枚举,则在尝试动画时出现以下错误:
//Animated done button with keyboard
origDoneFrame = btnDone.frame
btnDone.hidden = false
UIView.animateWithDuration(
animateDuration,
delay: Numbers.ANIMATE_DELAY,
options: nil,
animations: {
UIView.setAnimationCurve(animateCurve)
self.btnDone.frame = CGRectMake(self.btnDone.frame.origin.x + kbHeight, self.btnDone.frame.origin.y, self.btnDone.frame.size.width, self.btnDone.frame.size.height)
return Void()
},
completion: {finished in
return Void()
}
)
Run Code Online (Sandbox Code Playgroud)
有没有办法使用int设置曲线?
尝试使用int曲线:
UIView.animateWithDuration(
animateDuration,
delay: Numbers.ANIMATE_DELAY,
options: UIViewAnimationOptions(animateCurve << 16),
animations: {
self.btnDone.frame = CGRectMake(self.btnDone.frame.origin.x + kbHeight, self.btnDone.frame.origin.y, self.btnDone.frame.size.width, self.btnDone.frame.size.height)
return Void()
},
completion: {finished in
return Void() …Run Code Online (Sandbox Code Playgroud) 我试图使用下面的代码渲染部分jbuilder文件
json.(@request, :id)
json.profile do
json.partial! partial: 'users/user_reduced', user: @request.user
end
Run Code Online (Sandbox Code Playgroud)
部分在下面(users/_user_reduced.json.jbuilder)
json.(user, :id, :name, :sex)
Run Code Online (Sandbox Code Playgroud)
但是,我收到错误:
ActionView::Template::Error (undefined local variable or method `user' for #<#<Class:0x007fe4ebc91878>:0x007fe4ebe599f8>):
Run Code Online (Sandbox Code Playgroud)
就像没有设置本地用户变量一样.将局部变量设置为jbuilder部分路径的语法是什么?
一旦条件满足,是否可以让SQL停止检查WHERE子句?例如,如果我有如下声明:
SELECT * FROM Table1
WHERE Table1.SubID = (SELECT TOP 1 SubID FROM Table2 ORDER BY Date DESC)
OR Table1.OrderID = (SELECT TOP 1 OrderID FROM Table2 ORDER BY Date DESC)
Run Code Online (Sandbox Code Playgroud)
第一次检查后是否可以停止执行?实质上,只应使用where子句中的两个检查中的一个,优先于第一个.以下示例案例.
示例案例:
情况1
Table1 SubID=600 OrderID=5
Table2 TOP 1 SubID=NULL
Table2 TOP 1 OrderID=5
Matches the OrderID to 5
Run Code Online (Sandbox Code Playgroud)
案例2
Table1 SubId=600 OrderId=5
Table2 Top 1 SubID=600
Table2 Top 1 OrderID=3
Matches to SubID=600, not OrderID=3
Run Code Online (Sandbox Code Playgroud)
鉴于建议的答案,with似乎是解决SQL本身无法做到的最佳解决方案.对于我的具体情况,问题出在试图将其放入时outer apply,如下所示.
SELECT * FROM tbl_MainFields
OUTER APPLY
( …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个将更改对象属性的序列化程序.
例:
class testobj{
var prop1:Int = 3
var prop2:String = "Hello"
var prop3:Dictionary<String,String> = Dictionary<String,String>()
}
Run Code Online (Sandbox Code Playgroud)
我知道我可以使用访问属性的名称和类型
reflect(testobjc())[0].1
Run Code Online (Sandbox Code Playgroud)
和
var tester = testobj()
_std_lib_DemangledTypeName(tester.prop1)
Run Code Online (Sandbox Code Playgroud)
但我想做的事情是这样的
var tester = testobj()
for(var x:Int = 0; x < reflect(testobj()).count; x++){
if(_std_lib_DemangledTypeName(tester.(reflect(testobj())[0].1)) == "Swift.String"){
tester.(reflect(testobj())[0].1) = "World!"
}
}
Run Code Online (Sandbox Code Playgroud)
本质上,我想遍历为给定类列出的所有属性,并在该类的新创建的对象上设置属性.任何指导将不胜感激.快速反射对我来说是新的.
我试图使用RegAsm注册.dll.它是一个.NET 2.0 DLL.所有课程都是公开的,ComVisible是真实的.我仍然得到RA0000:没有类型被注册错误.下面是代码和assemblyinfo.任何帮助都会很棒,谢谢!
STARTelnet.cs
/**
*Steven T. Norris Created: 3/27/2012
*Last Updated By: Steven T. Norris Last Updated On: 3/27/2012
*
*/
using System;
using MinimalisticTelnet;
using System.Net.Sockets;
/**
* @brief Used to connect to, read, and respond to a STAR terminal session.
*
* Steven T. Norris Created: 3/27/2012
*/
namespace STARTelnet
{
/**
* Class used to connect to, read, and respond to a STAR terminal session.
*/
public class STARConnection
{
private TelnetConnection conn;
private string output; …Run Code Online (Sandbox Code Playgroud) 我有一个表格
<form id="form" action="" method="post" runat="server">
Run Code Online (Sandbox Code Playgroud)
通过C#代码隐藏访问时
HtmlForm form = (HtmlForm)this.FindControl("form");
Run Code Online (Sandbox Code Playgroud)
并试图改变行动
form.Attributes.Add("action","./newpage.aspx?data=data");
Run Code Online (Sandbox Code Playgroud)
要么
form.Attributes["action"] = "./newpage.aspx?data=data");
Run Code Online (Sandbox Code Playgroud)
没有改变.表单仍然路由到同一页面.如何在代码隐藏中动态更改表单的操作?
额外细节:我有一个具有get变量的页面.需要在表单的操作部分中发送get变量.所以,page1响应有getvar1.page1上的表单需要发送其发布数据和getvar1.我打算通过代码隐藏在表单的操作中调整它,但是想避免使用InnerHtml来编写整个表单.霍莉建议使用javascript,但我还没有找到一个用javascript获取GET变量的好方法......为群众提供更多信息.
答案解释:我选择了@HollyStyles提到的路线.在ajax调用完成后,我使用javascript来更改表单操作.但是,标记正确的答案是通过代码隐藏实现此目的的正确方法.
我有一个方法在UICollectionViewCell中调用下面的代码.该单元具有对UICollectionView和它所基于的数组的引用.以下代码失败并显示错误:
2014-11-20 13:41:08.976 MyApp[954:304515] *** Assertion failure in -[UICollectionView _endItemAnimations], /SourceCache/UIKit/UIKit-3318.16.14/UICollectionView.m:3917
2014-11-20 13:41:08.978 MyApp[954:304515] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of items in section 0. The number of items contained in an existing section after the update (1) must be equal to the number of items contained in that section before the update (1), plus or minus the number of items inserted or deleted from that section (0 inserted, 1 deleted) and plus …Run Code Online (Sandbox Code Playgroud) swift ×5
ios ×3
c# ×2
ruby ×2
asp.net ×1
avfoundation ×1
boolean ×1
code-behind ×1
dictionary ×1
dll ×1
forms ×1
indexing ×1
jbuilder ×1
keyboard ×1
naming ×1
partials ×1
reflection ×1
regasm ×1
select ×1
sql ×1
sql-server ×1
t-sql ×1
where ×1