如何在Swift中保护(如ruby)变量或函数?我知道斯威夫特只有3个级别但是有可能吗?
访问级别
Swift为代码中的实体提供三种不同的访问级别.这些访问级别与定义实体的源文件相关,也与源文件所属的模块相关.
- 公共访问使实体可以在其定义模块的任何源文件中使用,也可以在来自导入定义模块的另一个模块的源文件中使用.在指定框架的公共接口时,通常使用公共访问.
- 内部访问使实体可以在其定义模块的任何源文件中使用,但不能在该模块之外的任何源文件中使用.在定义应用程序或框架的内部结构时,通常使用内部访问.
- 专用访问将实体的使用限制在其自己的定义源文件中.使用私有访问隐藏特定功能的实现细节.
公共访问是最高(限制性最小)的访问级别,私有访问是最低(或限制性最强)的访问级别
目前我只看到一个解决方案 - 在单个文件中编写带有私有修饰符和子类的父类,但这有点痛苦.
我看到织物上发生了数十次撞击事故
Fatal Exception: NSInvalidArgumentException
-[LAContext biometryType]: unrecognized selector sent to instance 0x1c066aa00
Run Code Online (Sandbox Code Playgroud)
这很奇怪,因为我只在iOS 11+上调用LAContext上的biometryType.
代码:
private static var biometryType: BiometryType? {
let context = LAContext()
guard context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil),
context.evaluatedPolicyDomainState == BiometryManager.savedPolicyDomainState else { return nil }
if #available(iOS 11.0, *) {
switch context.biometryType {
case .typeFaceID: return .typeFaceID
case .typeTouchID: return .typeTouchID
case .none: return nil
}
}
return .typeTouchID
}
Run Code Online (Sandbox Code Playgroud)
有什么建议?
我唯一的线索是所有崩溃都与11.0.0有关.因此,Apple可能在11.0.0中添加了biometryType,但稍后.
链接:
https://developer.apple.com/documentation/localauthentication/lacontext/2867583-biometrytype
我试图了解它是如何工作的:
1> func returnNone() -> String? { return .None }
2> returnNone() == nil
$R0: Bool = true
3> returnNone() == .None
$R1: Bool = true
Run Code Online (Sandbox Code Playgroud)
为什么.None是平等的nil.
在enum定义中我没有看到任何关于它的内容:
public enum Optional<Wrapped> : _Reflectable, NilLiteralConvertible {
case None
case Some(Wrapped)
/// Construct a `nil` instance.
public init()
/// Construct a non-`nil` instance that stores `some`.
public init(_ some: Wrapped)
/// If `self == nil`, returns `nil`. Otherwise, returns `f(self!)`.
@warn_unused_result
@rethrows public func map<U>(@noescape f: (Wrapped) throws …Run Code Online (Sandbox Code Playgroud) 我正在尝试执行下一个代码int((226553150 * 1023473145) / 5),python3给了我一个答案46374212988031352.但是ruby和swift给了我一个答案46374212988031350.
我错过了什么?
我希望能够以本地化形式格式化和打印速度。我找到了一些可以做到这一点的豆荚,但我正在寻找嵌入式解决方案(如果可能的话)。
目前我接下来做:
let unit = HKUnit.meterUnit(with: .kilo).unitDivided(by: .hour())
let output = HKQuantity(unit: unit, doubleValue: 12.5).description
Run Code Online (Sandbox Code Playgroud)
但在这种情况下,我无法调整像 useh而不是hr.
现在,我使用版本控制对数据库进行任何更改。但这带来了一些问题。例如,很难将具有新db版本的功能分支合并到master / dev中,在那里有人也添加了新版本。
所以我的问题是:在不添加新版本的情况下在单个xcdatamodel中更改db是否安全?我已经尝试过了,但是它可以工作,但是在互联网上到处都可以看到警告,提示您一定不要这样做。
iOS9以上版本。
我发现了这个:https : //stackoverflow.com/a/37264096/5328417但它没有证据
我在相同的助手中进行了一些迁移
private
def add_earthdistance_index table_name, options = {}
execute "CREATE INDEX %s_earthdistance_ix ON %s USING gist (ll_to_earth(%s, %s));" %
[table_name, table_name, 'latitude', 'longitude']
end
def remove_earthdistance_index table_name
execute "DROP INDEX %s_earthdistance_ix;" % [table_name]
end
Run Code Online (Sandbox Code Playgroud)
而且我试图避免每次都将它们粘贴粘贴。有什么方法可以在迁移之间共享代码而无需猴子修补基类?我想找到类似concerns模型的东西。
是否可以在 Apple Watch 上通过 Siri 开始/停止锻炼?我相信它必须有效,但我找不到任何关于它的文档。
我只找到它http://jamesonquave.com/blog/adding-siri-to-ios-10-apps-in-swift-tutorial/但它适用于 iOS 而不适用于 watchOS。