我想以12小时格式获取当前时间。如果时间是18:36,那么我想要的格式应该是06:35 PM。为此,我使用了下面的代码,但它没有给我所需的format.I得到这样的格式。
let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "h:mm a"
let date22 = dateFormatter.string(from: date)
Run Code Online (Sandbox Code Playgroud) 我在我的应用中显示本地和远程通知.现在有一种情况,如果通知是本地的,那么我想采取不同的行动,或者如果通知是远程的,那么我想采取一些不同的行动.
直到iOS 9我使用下面的代码来检测通知是本地还是远程.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
if launchOptions?[UIApplicationLaunchOptionsKey.localNotification] != nil {
// Do what you want to happen when a remote notification is tapped.
}
return true
}
Run Code Online (Sandbox Code Playgroud)
但是在iOS 10中这种方法已被弃用,所以现在如何确保通知是本地的还是远程的?
我有一个 UIButton。我想设置按钮的渐变如下。
我试过下面的代码,但它没有按照屏幕截图设置颜色。
func applyGradient(colours: [UIColor]) -> Void {
self.applyGradient(colours: colours, locations: nil)
}
func applyGradient(colours: [UIColor], locations: [NSNumber]?) -> Void {
let gradient: CAGradientLayer = CAGradientLayer()
gradient.frame = self.bounds
gradient.colors = colours.map { $0.cgColor }
gradient.locations = locations
self.layer.insertSublayer(gradient, at: 0)
}
Run Code Online (Sandbox Code Playgroud) 我遇到了必须在 Mac OS/OS X 上运行 Go 构建的情况。构建将从 Linux 操作系统生成,并且我必须在 Mac OS/OS X 上运行该构建。
我尝试使用以下命令为 Mac 生成跨平台构建并生成构建。
env GOOS=linux GOARCH=amd64 go build
Run Code Online (Sandbox Code Playgroud)
这生成了一个 Go 构建,但我将此构建移动到 Mac,它显示了 .dms 文件扩展名。
现在我有两个问题
我有两个 ISO 格式的日期字符串。我正在使用 moment js 计算它们之间的分钟差。
var currenttime = new Date().toISOString();
var expiretime = '2020-06-05T12:18:33.000Z';
let minutes = moment(expiretime, 'YYYY-MM-DD[T]HH:mm:ss. SSS[Z]').diff(moment(currenttime, 'YYYY-MM-DD[T]HH:mm:ss. SSS[Z]'), 'minutes');
console.log(minutes)
Run Code Online (Sandbox Code Playgroud)
现在我有两个问题
这是计算分钟差的最佳方法吗?
当我new Date().toISOString()之前运行该值z时应该是时区但每次重新启动时它都会改变?
请让我知道是什么问题?
I have JSON file which has json data of size 914MB. I loading the file with fs-extra and parsing it. But when i parse it get error as
cannot create a string longer than 0x1fffffe8 characters
Below is code
const fs = require('fs-extra');
const rawdata = fs.readFileSync('src/raw.json');
const data = JSON.parse(rawdata);
Run Code Online (Sandbox Code Playgroud)
I am running the project with npm and to run i have below command in package.json.
"scripts": {
"start:dev": "cross-env NODE_OPTIONS='--max-old-space-size=4096' ts-node -r tsconfig-paths/register ./src --env=development",
}
Run Code Online (Sandbox Code Playgroud) 我想在swift 3中将backbutton的标题更改为任何名称.我尝试了很多方法,但它们都没有为我工作.
self.navigationItem.backBarButtonItem?.title="Title"
self.navigationController?.navigationItem.backBarButtonItem?.title="Title"
Run Code Online (Sandbox Code Playgroud)
仅供参考,我在appdelegate中编写了以下代码.
let backImage : UIImage = UIImage(named:"backArrow")!
UINavigationBar.appearance().barTintColor = UIColor(red: 0.0/255.0, green: 0.0/255.0, blue: 0.0/255.0, alpha: 1.0)
UINavigationBar.appearance().tintColor = UIColor.white
UINavigationBar.appearance().backIndicatorImage = backImage
UINavigationBar.appearance().backIndicatorTransitionMaskImage = backImage
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName : UIColor.white]
UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffsetMake(0, 0), for: .default)
IQKeyboardManager.sharedManager().enable = true
self.window?.backgroundColor = UIColor.white
Run Code Online (Sandbox Code Playgroud) uinavigationbar uinavigationcontroller uinavigationitem swift
我正在使用下面的代码来显示文档选择器。当我显示选择器时,我使用下面的代码
let documentPickerController = UIDocumentPickerViewController(documentTypes: [String(kUTTypeText), String(kUTTypePDF), String(kUTTypePNG), String(kUTTypeJPEG), String(kUTTypePlainText), String(kUTTypeImage)], in: .import)
Run Code Online (Sandbox Code Playgroud)
上面的代码向我显示了iCloud中的所有文件,但不允许我选择doc,docx文件。这些文件显示为已禁用。
但是当我"public.data"在UIDocumentPickerViewController构造函数中添加为元素时,它允许我选择doc,docx文件和文件未显示为已禁用。
请告诉我为什么会这样吗?
I am uploading file in swift with the help of URLSession. But issue is I don't get progress for the upload. I am not using any multipart request. I am just sending data of video in body of request.
let urlStr = UserDefaults.standard.value(forKey: "Resumable") as? String ?? ""
let url = URL(string: urlStr)
do{
var request = try URLRequest(url: url!, method: .put)
// request.setValue("application/json", forHTTPHeaderField: "Accept")
request.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization")
// request.setValue("300000", forHTTPHeaderField: "X-Upload-Content-Length")
request.setValue("video/*", forHTTPHeaderField: "Content-Type")
request.setValue("278", forHTTPHeaderField: "Content-Length") …Run Code Online (Sandbox Code Playgroud)