我试图在Xcode 9 iPhone 7 plus模拟器中运行示例ARKit.但它失败了.是否有可能在iOS模拟器中检查ARKit项目.
如何快速开始和结束一周?这是我的代码
extension Date {
var startOfWeek: Date? {
let gregorian = Calendar(identifier: .gregorian)
guard let sunday = gregorian.date(from: gregorian.dateComponents([.yearForWeekOfYear, .weekOfYear], from: self)) else { return nil }
return gregorian.date(byAdding: .day, value: 1, to: sunday)
}
var endOfWeek: Date? {
let gregorian = Calendar(identifier: .gregorian)
guard let sunday = gregorian.date(from: gregorian.dateComponents([.yearForWeekOfYear, .weekOfYear], from: self)) else { return nil }
return gregorian.date(byAdding: .day, value: 7, to: sunday)
}
}
Run Code Online (Sandbox Code Playgroud)
我这样打电话
let startWeek = Date().startOfWeek
let endWeek = Date().endOfWeek
print(startWeek!)
print(endWeek!)
var dateFormat1 …Run Code Online (Sandbox Code Playgroud) 我刚刚更新到 XCode 11.4,我的一些代码已经停止工作。我@Published在一个ObservableObject. 以前,当我更新结构上的属性时,该didSet方法会触发已发布的属性,但现在情况不再如此。在 Swift 的最新更新中,这种行为是否有可能被设计改变了?
这是一个简单的例子:
import SwiftUI
struct PaddingRect {
var left: CGFloat = 20
var right: CGFloat = 20
}
final class SomeStore : ObservableObject {
@Published var someOtherValue: String = "Waiting for didSet"
@Published var paddingRect:PaddingRect = PaddingRect() {
didSet {
someOtherValue = "didSet fired"
}
}
}
struct ObserverIssue: View {
@ObservedObject var store = SomeStore()
var body: some View {
VStack {
Spacer()
Rectangle()
.fill(Color.yellow)
.padding(.leading, store.paddingRect.left)
.padding(.trailing, …Run Code Online (Sandbox Code Playgroud) 我一直试图转换这个代码,我从这个例子(在Objective-c中)没有运气.
String *path; // contains the file path
// Get the UTI from the file's extension:
CFStringRef pathExtension = (__bridge_retained CFStringRef)[path pathExtension];
CFStringRef type = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, pathExtension, NULL);
CFRelease(pathExtension);
// The UTI can be converted to a mime type:
NSString *mimeType = (__bridge_transfer NSString *)UTTypeCopyPreferredTagWithClass(type, kUTTagClassMIMEType);
if (type != NULL)
CFRelease(type);
Run Code Online (Sandbox Code Playgroud)
我的代码是这样的
import MobileCoreServices
let path: String?
let pathExt = path.pathExtension as CFStringRef
let type = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, pathExtension, NULL);
let mimeType = UTTypeCopyPreferredTagWithClass(type, kUTTagClassMIMEType)
if type != Null …Run Code Online (Sandbox Code Playgroud) 我们的应用程序支持 iOS 12 及更高版本,但是我们在应用程序中有两个新的本地框架“Jello”和“Wizdom”,但它们仅支持 iOS 13 及更高版本(因此它们可以使用 Combine 和 SwiftUI)。
该应用程序与 Jello、Wizdom、Combine 和 SwiftUI 的链接很弱。该应用程序的主要 BaseUI 模块是实际导入 Jello 的部分。BaseUI 支持 iOS 12 及更高版本,因此它与 Jello 等的链接也很弱。
但是,我们遇到了一个问题,即 BaseUI 由于以下错误而无法编译:Compiling for iOS 12.0, but module 'Jello' has a minimum deployment target of iOS 13.0.
如何在 iOS 13 可用的情况下使导入成为条件(即,如果 iOS 13 不可用,则不要导入它)?
(到目前为止,我发现的唯一解决方法是在 Jello 周围创建一个 Objective C 包装器并通过该包装器访问它,但这很笨拙且笨拙。我也尝试用它包装整个文件,#if canImport(SwiftUI) ... #endif但这也不起作用,因为它似乎这只是一个编译时检查。)
class ViewController: UIViewController {
var shadow : UIView!
override func viewDidLoad() {
super.viewDidLoad()
shadow = UIView(frame: CGRect(x: 50,y: 50,width: 150,height:150))
shadow.backgroundColor = .red
shadow.dropShadow()
self.view.addSubview(shadow)
}
@IBAction func btnActn(_ sender: Any) {self.shadow.frame = CGRect(x: 50,y: 50,width: 150,height: 50)
}
}
extension UIView {
func dropShadow(scale: Bool = true) {
layer.masksToBounds = false
layer.shadowColor = UIColor.black.cgColor
layer.shadowOpacity = 0.5
layer.shadowOffset = CGSize(width: 1, height: 1)
layer.shadowRadius = 2
layer.shadowPath = UIBezierPath(rect: bounds).cgPath
layer.shouldRasterize = true
layer.rasterizationScale = scale ? UIScreen.main.scale …Run Code Online (Sandbox Code Playgroud) 我需要在用户登录时启动我的Mac应用程序.
这就是我做的:
我创建了一个新的Coca Application Target.
•构建设置将"跳过安装"设置为"是"
•Info.plist"应用程序仅后台"到"是"
•在主应用程序和帮助程序应用程序上启用了沙盒.
•将复制文件阶段添加到主应用程序:Wrapper,Contents/Library/LoginItems,添加了Helper.app
Helper应用程序的AppDelegate.swift
import Cocoa
import ServiceManagement
extension Notification.Name {
static let killLauncher = Notification.Name("killLauncher")
}
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
@objc func terminate() {
NSApp.terminate(nil)
}
func applicationDidFinishLaunching(_ aNotification: Notification) {
print("hi")
let mainAppIdentifier = "co.myprogress.osx"
let runningApps = NSWorkspace.shared.runningApplications
let isRunning = !runningApps.filter { $0.bundleIdentifier == mainAppIdentifier }.isEmpty
if !isRunning {
DistributedNotificationCenter.default().addObserver(self,
selector: #selector(self.terminate),
name: .killLauncher,
object: mainAppIdentifier)
let path = Bundle.main.bundlePath as NSString
var components = path.pathComponents
components.removeLast()
components.removeLast() …Run Code Online (Sandbox Code Playgroud) 我尝试使用 Swift 在 Mac OS 上显示一些通知横幅。但我只在通知中心得到它们,而不是作为横幅。
你有想法吗?这是我的简单代码:
func showNotification() -> Void {
let notification = NSUserNotification()
notification.title = "Title of notification"
notification.subtitle = "Subtitle of notification"
notification.soundName = NSUserNotificationDefaultSoundName
NSUserNotificationCenter.default.deliver(notification)
}
@IBAction func btnPressed(_ sender: NSButton) {
showNotification()
testLbl.stringValue = "Button was pressed"
}
Run Code Online (Sandbox Code Playgroud)