Warning
The following guide need to disable SIP to work.
Please confirm the risk of disabling the SIP by yourself.
Another solution which does not require disabling SIP is currently under investigation.
Reboot into Recovery OS + Disable SIP
Swift Macro
分为两部分,一部分为宏的具体实现(编译器插件),一部分为Macro Lib
用于导出宏定义以及所需要的附属代码,这里说的不使用SPM
指的是编译器插件这部分Xcode
使用SPM
集成Macro
时,在编译命令中通过-load-plugin-executable
参数指定了对应宏实现的插件可执行文件路径swift
源码中也找到了相关参数TypeCheckMacros.cpp TypeCheckMacros.cppswift
源码中可得知,宏实现插件即可以是动态库(dylib)也可以是可执行文件-plugin-path <dylib path>
加载Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/Lib/swift/host/plugins
SPM
也可以直接通过Xcode
创建命令行程序项目,完成宏实现代码编写@propertyWrapper | |
public struct PublishedObject<Value: ObservableObject> { // wrappedValue 要求符合 ObservableObject | |
public var wrappedValue: Value | |
public init(wrappedValue: Value) { | |
self.wrappedValue = wrappedValue | |
} | |
public static subscript<OuterSelf: ObservableObject>( | |
_enclosingInstance observed: OuterSelf, |
// | |
// ViewController.swift | |
// WatchAndLearn | |
// | |
// Created by Michael Sepcot on 9/18/19. | |
// Copyright © 2019 Michael Sepcot. All rights reserved. | |
// | |
import UIKit | |
import HealthKit |
On Mac, SwiftUI's .onHover
closure is not always called on mouse exit, particularly with high cursor velocity. A grid of targets or with finer target shapes will often have multiple targets falsely active after the mouse has moved on.
It is easy to run back to AppKit's safety. Below is a SwiftUI-like modifier for reliable mouse-tracking. You can easily adapt it for other mouse tracking needs.
import SwiftUI
import SwiftUI | |
import PlaygroundSupport | |
struct Desktop: View { | |
var body: some View { | |
ZStack { | |
// Image(uiImage: #imageLiteral(resourceName: "IMG_6281.JPG")) | |
Color(UIColor.systemBlue) | |
macOS() | |
} |
// | |
// FacebookAuth.swift | |
// GitHub: ethanhuang13 | |
// Twitter: @ethanhuang13 | |
import AuthenticationServices | |
import SafariServices | |
/* | |
Updated: |
// | |
// BlurryVibrantView.swift | |
// | |
// | |
// Created by Adam Bell on 11/9/19. | |
// Copyright © 2019 Adam Bell. All rights reserved. | |
// | |
import SwiftUI | |
import UIKit |
Here's what needs to be done in order to use security scoped bookmarks on Mac Catalyst:
You need an entitlement: "com.apple.security.files.bookmarks.app-scope" needs to be se to 1.
Pass both NSURLBookmarkCreationWithSecurityScope
and NSURLBookmarkCreationSecurityScopeAllowOnlyReadAccess
when creating the bookmark.
Note: The headers mark these API as unavailable for iOS, and this indeed does only work on Mac and not iOS. However, Mac Catalyst really is a Mac app, so using these values is fine. In order to allow compilation, use following: