我想将转换Float成Int斯威夫特.像这样的基本转换不起作用,因为这些类型不是基元,与Objective-C中的floats和ints 不同
var float: Float = 2.2
var integer: Int = float as Float
Run Code Online (Sandbox Code Playgroud)
但是这会产生以下错误消息:
'Float'不能转换为'Int'
知道如何将属性转换Float为Int?
关于Core Location的一个简单问题,我正在尝试计算两点之间的距离,代码如下:
-(void)locationChange:(CLLocation *)newLocation:(CLLocation *)oldLocation
{
// Configure the new event with information from the location.
CLLocationCoordinate2D newCoordinate = [newLocation coordinate];
CLLocationCoordinate2D oldCoordinate = [oldLocation coordinate];
CLLocationDistance kilometers = [newCoordinate distanceFromLocation:oldCoordinate] / 1000; // Error ocurring here.
CLLocationDistance meters = [newCoordinate distanceFromLocation:oldCoordinate]; // Error ocurring here.
}
Run Code Online (Sandbox Code Playgroud)
我在最后两行收到以下错误:
错误:无法转换为指针类型
我一直在搜索谷歌,但我找不到任何东西.
我使用Objective-C下面的代码来弹出特定的代码ViewController.
for (UIViewController *controller in self.navigationController.viewControllers) {
if ([controller isKindOfClass:[AnOldViewController class]]) {
//Do not forget to import AnOldViewController.h
[self.navigationController popToViewController:controller
animated:YES];
break;
}
}
Run Code Online (Sandbox Code Playgroud)
我怎么能在Swift中做到这一点?
我只是想问一下如何确定在静音推送上要采取的行动:
这是我发给客户的aps:
"aps": {
"content-available": 1
}
Run Code Online (Sandbox Code Playgroud)
我现在的问题是当我添加类型:"Order_Update"以确定静默推送是针对订单更新它显示警报通知
如何在 SwiftUI 中更改选择器框架?
Picker(selection: .constant(1), label: Text("Picker")) {
Text("Hello").tag(1)
Text("World").tag(2)
}
.frame(height: 60)
.pickerStyle(SegmentedPickerStyle())
Run Code Online (Sandbox Code Playgroud)
我们希望选择器高度等于60,但事实并非如此。
这让我疯了.
在雨燕2.2,这使得它不可能下标String有Int.例如:
let myString = "Test string"
let index = 0
let firstCharacter = myString[index]
Run Code Online (Sandbox Code Playgroud)
这将导致编译错误,说
'subscript'不可用:不能使用Int下标String,请参阅文档注释以供讨论
我看到的一个解决方法是将整数转换为索引类型,但我无法弄清楚如何...
我需要以.xib编程方式重新创建基于布局的布局。
我在很大程度上能够实现这一点,但是,无法设置我的一位主播的优先级。
我试图在代码中重现的设置是:
我以为我可以设置它,setContentHuggingPriority(.init(999), for: .vertical)但这没有效果。
如何在代码中定位此属性?
是否可以在UIButton中加粗字体?有了标签,它非常简单,例如:
label.font = UIFont(name:"HelveticaNeue-Bold", size: 16.0)
Run Code Online (Sandbox Code Playgroud)
但这不适用于按钮.
我正在尝试创建一个简单的过滤器应用程序,在按下按钮时过滤显示的图像。
@IBAction func applyFilter(sender: AnyObject) {
// Create an image to filter
let inputImage = CIImage(image: photoImageView.image)
// Create a random color to pass to a filter
let randomColor = [kCIInputAngleKey: (Double(arc4random_uniform(314)) / 100)]
// Apply a filter to the image
let filteredImage = inputImage.imageByApplyingFilter("CIHueAdjust", withInputParameters: randomColor)
// Render the filtered image
let renderedImage = context.createCGImage(filteredImage, fromRect: filteredImage.extent())
// Reflect the change back in the interface
photoImageView.image = UIImage(CGImage: renderedImage)
}
Run Code Online (Sandbox Code Playgroud)
我不断收到错误:
可选类型“UIImage?”的值 没有解开。
我在这里做错了什么?我是 Swift 初学者。
struct CardView: View {
private var name: String = "Random Name"
private var color: Color = Color.red
private var CardContent: some View {
HStack(alignment: .top) {
Text(name)
.font(.system(size: 16, weight: .medium, design: .rounded))
.frame(width: 110, height: 80, alignment: .top)
}
.padding(.top, 20)
.frame(width: 200, height: 190, alignment: .top)
.background(color)
.clipShape(RoundedRectangle(cornerRadius: 30, style: .continuous))
}
var body: some View {
CardContent
.contentShape(RoundedRectangle(cornerRadius: 30, style: .continuous))
.contextMenu {
Button(action:{}){
HStack {
Image(systemName: "trash")
.foregroundColor(Color.red)
Text("Delete")
}
}
}
.shadow(color: color.opacity(0.5), radius: 10, …Run Code Online (Sandbox Code Playgroud)
在我的应用程序中,我有一个基于用户输入的PDF表单。我在PDF表单中强制输入该值。我ILPDFKit在我的应用程序中使用了pod来执行此操作(swift 3,但是由于PDFKit在iOS 11中已经存在,所以我想知道使用PDFKit是否可以实现)。我使用的代码ILPDFKit是:
// set the pdf form as ILPDFDocument
let document = ILPDFDocument(resource:"ExamplePDFfrom")
// Manually set a form value for field name (created in adobe acrobat)
document.forms.setValue("David", forFormWithName: "FirstName")
Run Code Online (Sandbox Code Playgroud) 我想为a添加一些视图UIButton.例如,多个UILabels,UIImages等等.我添加了这些视图,但它们没有获得触摸事件.我怎样才能将触摸事件传递给UIButton?
谢谢
输出为15(在f中,x为10,y为7),具有以下内容:
var x = 5;
function f(y) { return (x + y) - 2};
function g(h) { var x = 7; return h(x) };
{ var x = 10; z = g(f); console.log(z) };
Run Code Online (Sandbox Code Playgroud)
为什么x取第4行而不是第1行的值(为什么不是第3行)?
swift ×9
ios ×8
swiftui ×2
uibutton ×2
annotations ×1
autolayout ×1
casting ×1
contextmenu ×1
javascript ×1
label ×1
objective-c ×1
optional ×1
pdfkit ×1
scoping ×1
string ×1
subscript ×1
swift2 ×1
swift2.2 ×1
uifont ×1
uiimage ×1
uiview ×1