我有一个带有1个可选字段和1个非可选字段的类,它们都具有Type AnotherClass并且还符合CustomProtocol:
protocol CustomProtocol {}
class CustomClass: CustomProtocol {
var nonoptionalField: AnotherClass = AnotherClass()
var optionalField: AnotherClass?
}
class AnotherClass: CustomProtocol {
}
Run Code Online (Sandbox Code Playgroud)
现场nonoptionalField是类型AnotherClass,符合CustomProtocol.
另一方面,optionalField实际上是Optional <AnotherClass>,因此不符合CustomProtocol:
for field in Mirror(reflecting: CustomClass()).children {
let fieldMirror = Mirror(reflecting: field.value)
if fieldMirror.subjectType is CustomProtocol.Type {
print("\(field.label!) is \(fieldMirror.subjectType) and conforms CustomProtocol")
} else {
print("\(field.label!) is \(fieldMirror.subjectType) and DOES NOT conform CustomProtocol")
}
}
// nonoptionalField is AnotherClass …
Run Code Online (Sandbox Code Playgroud) 我已经实现了iOS 11功能preferredsLargeTitles,并且效果很好。纵向模式按预期工作:
我知道大标题在横向模式下始终会保持折叠状态(小),这对我来说很好。问题是,当我尝试更改为横向然后再次更改为纵向时,默认情况下应以纵向模式将大标题扩展(大),但直到我向下滚动时才会显示:
我的代码看起来很简单:
if #available(iOS 11.0, *) {
navigationController?.navigationBar.prefersLargeTitles = true
navigationItem.largeTitleDisplayMode = .always
}
Run Code Online (Sandbox Code Playgroud)
我还尝试在tableView.contentInsetAdjustmentBehavior上使用不同的值,但未进行任何更改。我现在通过在方向更改后以编程方式向下滚动表格来解决此问题,但是我认为这只是一种解决方法(不是很好)。
那应该能按预期工作吗?我的实现中还剩下什么吗?有更好的解决方法吗?
我的 Android 项目有一个 (Windows) Jenkins 管道,我正在尝试获取文件versionName
中的定义build.gradle
。根据/sf/answers/3574698361/和/sf/answers/3320615861/我有以下设置:
构建.gradle
android {
defaultConfig {
versionCode 71
versionName "2.3.0.Beta10"
}
}
task versionName{
doLast {
println android.defaultConfig.versionName
}
}
Run Code Online (Sandbox Code Playgroud)
詹金斯文件
pipeline {
environment {
SERVER_PATH = '\\\\ARK_SRV\\Android\\'
}
agent any
stages {
stage('Create Directory') {
steps {
script {
def VERSION_NAME = bat (script: "./gradlew -q versionName", returnStdout: true).trim()
echo "Version Name: ${VERSION_NAME}"
def FINAL_DIR = SERVER_PATH + VERSION_NAME
echo "Final Directoy: ${FINAL_DIR}"
// ...
} …
Run Code Online (Sandbox Code Playgroud) 我想将Completable链接到可观察元素。调用flatMap之后,订阅似乎未调用onCompleted和onError回调。
var user = PublishRelay<User>()
func fetchUserInformation(_ userId: String) -> Completable {
return Completable.create { observer in
apiService.fetchInformation(for: userId, completion: { response in
if let name = response?.name {
user.accept(User(name: name))
observer(.completed)
} else {
observer(.error(ServiceError.userInformation))
}
})
return Disposables.create()
}
}
login()
.flatMap{ userId in fetchUserInformation(userId) }
.subscribe(
onCompleted: {
print("Success!") // Not being called at all
},
onError: { error in
print(error) // Not being called at all
}
).disposed(by: disposeBag)
Run Code Online (Sandbox Code Playgroud)
尽管正在调用fetchUserInformation和observer(.completed),并且成功获取了用户信息,但我无法在订阅时捕获 …
我试图使我的 API 服务尽可能通用:
API服务类
class ApiService {
func send<T>(request: RestRequest) -> T {
return request.parse()
}
}
Run Code Online (Sandbox Code Playgroud)
这样编译器就可以从请求类别中推断出响应类型,.auth
并且.data
:
let apiService = ApiService()
// String
let stringResponse = apiService.send(request: .auth(.signupWithFacebook(token: "9999999999999")))
// Int
let intResponse = apiService.send(request: .data(.content(id: "123")))
Run Code Online (Sandbox Code Playgroud)
我试图提出一个使用泛型和具有关联类型的协议的解决方案,以干净的方式处理解析。但是,我无法以简单且类型安全的方式将请求案例与不同的响应类型相关联:
protocol Parseable {
associatedtype ResponseType
func parse() -> ResponseType
}
Run Code Online (Sandbox Code Playgroud)
端点
enum RestRequest {
case auth(_ request: AuthRequest)
case data(_ request: DataRequest)
// COMPILER ERROR HERE: Generic parameter 'T' is not used in function signature
func parse<T: …
Run Code Online (Sandbox Code Playgroud) 在将我的cocoa框架项目转换为Swift 4后,类UIFontDescriptorFamilyAttribute现在是UIFontDescriptor.AttributeName.family,所以我更改了我的代码:
// Swift 3
UIFontDescriptor(fontAttributes: [UIFontDescriptorFamilyAttribute: fontFamiliy])
Run Code Online (Sandbox Code Playgroud)
至
// Swift 4
UIFontDescriptor(fontAttributes: [UIFontDescriptor.AttributeName.family: fontFamiliy])
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试 - pod spec lint - 我得到下一个错误:
- ERROR | [iOS] xcodebuild: SerializableLabel.swift:108:68: error: type 'UIFontDescriptor' has no member 'AttributeName'
Run Code Online (Sandbox Code Playgroud)
cocoapods还不知道Swift 4吗?我是否必须在配置中更新其他内容?
我的配置:
.podspec
s.pod_target_xcconfig = { 'SWIFT_VERSION' => '4.0' }
Run Code Online (Sandbox Code Playgroud)
的CocoaPods
$ pod --version
1.3.1
Run Code Online (Sandbox Code Playgroud) swift ×5
ios ×2
android ×1
cocoapods ×1
generics ×1
gradle ×1
gradlew ×1
ios11 ×1
jenkins ×1
observable ×1
orientation ×1
protocols ×1
rx-swift ×1
swift4 ×1
uitableview ×1