Post

Replies

Boosts

Views

Activity

How do I use reserved keyword `Type` in Swift?
I know, It doesn’t make sense. but I have no choice. There are 2 problems // problem1 let type = ReservedKeyword.`Type`(rawValue: 1) public class ReservedKeyword: Codable { 		public enum `Type`: Int, Codable { 				case zero = 0 				case one = 1 				case two = 2 				case three = 3 		} 		public var type: ReservedKeyword.`Type` 		 		public init(type: ReservedKeyword.`Type`) { 				self.type = type 		} 		 		private enum CodingKeys: String, CodingKey { 				case type 		} 		public required init(from decoder: Decoder) throws { 				let container = try decoder.container(keyedBy: CodingKeys.self) 				// problem2 				self.type = try container.decode(ReservedKeyword.`Type`.self, forKey: .type) 		} 		public func encode(to encoder: Encoder) throws { 				var container = encoder.container(keyedBy: CodingKeys.self) 				try container.encode(self.type, forKey: .type) 		} }
2
0
1.1k
Dec ’20
FileManager displayName(atPath:) no effect?
I logged in to macOS with my localization language. try to perform following code. but always get "Documents". What do I miss? Apple Swift version 5.2.4 macOS 10.15.6 Xcode 11.6 code let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true) if paths.count > 0 {     let doc = FileManager().displayName(atPath: paths[0])     print(doc) } result Documents
3
0
852
Sep ’20
Swift compiler error - No such module in Xcode 11.5
I have 2 targets and 1 CLibBSM module(SPM) in MyApp project in Xcode 11.51.MyApp(GUI App)2.Utility link to CLibBSM(Command Line Tool)Individual compile are very well.But When I copy Utility into MyApp at "Build Phases"(Wrapper-subpath:Contents/Library/LaunchServices) in MyApp that occurred "Swift compiler error - No such module `CLibBSM`" issue.Is it possible to solve this issue?CLibBSM/Package.swift(SPM)// swift-tools-version:5.2 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription let package = Package( name: "CLibBSM", products: [ // Products define the executables and libraries produced by a package, and make them visible to other packages. .library( name: "CLibBSM", targets: ["CLibBSM"]), ], dependencies: [ // Dependencies declare other packages that this package depends on. // .package(url: /* package url */, from: "1.0.0"), ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. // Targets can depend on other targets in this package, and on products in packages which this package depends on. .target( name: "CLibBSM", dependencies: []), .testTarget( name: "CLibBSMTests", dependencies: ["CLibBSM"]), ] )CLibBSM/Sources/CLibBSM/include/module.modulemap(SPM)module CLibBSM [system] { header "shim.h" link "bsm" export * }CLibBSM/Sources/CLibBSM/include/shim.h(SPM)#ifndef __CLIBBSM_SHIM_H__ #define __CLIBBSM_SHIM_H__ #import <sys/sysctl.h> #import <Foundation/Foundation.h> #import <unistd.h> #import <libproc.h> #import <pthread.h> #import <bsm/audit.h> #import <sys/ioctl.h> #import <sys/types.h> #import <bsm/libbsm.h> #import <bsm/audit_kevents.h> #import <security/audit/audit_ioctl.h> #import <sys/proc_info.h> #endifCLibBSM/Sources/CLibBSM/shim.c(SPM)//empty
0
0
1.9k
Jun ’20