在 Swift 包的清单中,您可以声明产品。对于这些产品,您可以定义它们的types. 一个选项是static,另一个选项是dynamic,或者您可以将其留空,Swift 包管理器将根据客户的首选项自动选择类型。
为什么我要选择将出售的库设为静态而不是动态,反之亦然?
如果库的使用者是 iOS 项目,那么这个决定会如何影响他们?
我正在像这样初始化我的领域实例:
private static let sUserRealm:Realm = try! Realm(configuration:Realm.Configuration(
fileURL: Bundle.main.url(forResource: "user" ,withExtension: "realm"),
inMemoryIdentifier: nil,
syncConfiguration: nil,
encryptionKey: nil,
readOnly: false,
schemaVersion: 0,
migrationBlock: sMigrationBlock,
deleteRealmIfMigrationNeeded: true,
objectTypes: nil))
Run Code Online (Sandbox Code Playgroud)
但是,我收到此错误:
fatal error: A Realm Configuration must specify a path or an in-memory
identifier.: file /Users/realm/workspace/Package iOS Swift/tightdb_objc/RealmSwift/RealmConfiguration.swift, line 201
Run Code Online (Sandbox Code Playgroud)
所有领域在关于创建多个领域的 swift 文档中都有这个例子,即使逐字复制也会引发相同的错误。如何创建和访问领域文件?
所以我有一个.png428x176 px:
我希望将其用作项目处于选定状态时的标签栏背景图像。问题是图像太大。所以现在,我正在探索不同的分辨率后缀:@ 1x,@ 2x,@ 3x。但是,无论我在图像文件名中附加哪一个,该图像对于选项卡栏项目的背景而言仍然太大,尽管随着分辨率提高,它的确会变小。如何确定此图像的正确尺寸?
请记住,这是任何特定UITabBarItem状态处于选定状态时的背景图像。它是指的整个宽度和高度UITabBarItem。我的标签栏将在屏幕的整个宽度上放置三个项目。
许多答案都提供了基于快速的解决方案,但是我要问的是我的图像应以像素为单位的尺寸,换句话说,我应该在包装中包括多少尺寸的图像,以便该图像适合所有屏幕尺寸的标签栏。我可以想象,由于UITabBar默认情况下a期望UIImage其selectionIndicatorImage字段为a UIImageView,而不是a ,因此必须存在一种解决方案,该解决方案不涉及修改the UITabBar并将其UIImageView作为子视图添加,并手动管理图像视图应位于的位置,根据UITabBarItem当前选择的。
如何创建三角形UIImage?这就是我现在的操作方式,但是它根本不产生任何图像。
extension UIImage {
static func triangle(side: CGFloat, color: UIColor)->UIImage {
UIGraphicsBeginImageContextWithOptions(CGSize(width: side, height: side), false, 0)
let ctx = UIGraphicsGetCurrentContext()!
ctx.saveGState()
ctx.beginPath()
ctx.move(to: CGPoint(x: side / 2, y: 0))
ctx.move(to: CGPoint(x: side, y: side))
ctx.move(to: CGPoint(x: 0, y: side))
ctx.move(to: CGPoint(x: side / 2, y: 0))
ctx.closePath()
ctx.setFillColor(color.cgColor)
ctx.restoreGState()
let img = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
return img
}
}
Run Code Online (Sandbox Code Playgroud) 如果我在封闭中弱引用自我:
{[weak self] in self!.doSomethinmg()}
Run Code Online (Sandbox Code Playgroud)
并且self已经解除分配,但关闭仍然存在.是否有可能self在闭包中在将来的某个时刻变为非零 - 指向由运行时环境确定的一些随机新对象?