如何在 Typescript 中使用可选类型?例如,我有一个名为的对象Conversation
:
class Conversation {
lastMessage?: Message
}
class Message {
text: string
}
Run Code Online (Sandbox Code Playgroud)
我想通过对象text
从Message
对象获得可为空Conversation
。
const lastMessageText?: string = conversation?.lastMessage.text
Run Code Online (Sandbox Code Playgroud)
但这种语法不起作用。?
谈话后我无法写作。
如何打开详细模块或地铁捆绑器的日志在哪里?它总是卡住,我不知道为什么。我在 KotlinJS 中使用默认的 React Native 项目。
我正在尝试创建带有代码样式检查和其他错误的预提交挂钩。它是 Android Studio 中的一个多模块项目(java 和 kotlin)。我希望使用lint,但没有运气。
我的条件是仅检查新文件和修改过的文件(基线按 ofc 顺序),因为项目太大,无法对每个文件的每次提交进行检查。
我的sh命令如下所示:
git diff --name-only HEAD | xargs -I '{}' ./gradlew lint {}\;
Run Code Online (Sandbox Code Playgroud)
它翻译为:
./gradlew lint /path/to/the/file.java
Run Code Online (Sandbox Code Playgroud)
但它总是无法尝试找到名为“文件路径”的任务。
当我尝试使用Android SDK中的lint时,它只会打印main: Error: "main" is a Gradle project. To correctly analyze Gradle projects, you should run "gradlew :lint" instead.
有什么建议吗?
无论我以哪种方式实现组合凭据管理器,我都会遇到异常
GetCredentialCancellationException: activity is canceled by the user.
经理会显示一个与我的 Google 帐户的对话框,我选择一个,然后出现一个“同意屏幕”,其中带有“继续使用我”按钮。单击该按钮后,我得到了上面的异常。
我不知道我做错了什么。
我的图书馆:
androidx.credentials.credentials:credentials:1.2.0-beta03
androidx.credentials.credentials:credentials-play-services-auth:1.2.0-beta03
com.google.android.gms:play-services-auth:20.7.0
基本演示代码:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
WindowCompat.setDecorFitsSystemWindows(window, false)
super.onCreate(savedInstanceState)
lifecycleScope.launch {
CredentialManager.create(this@MainActivity.applicationContext).getCredential(
context = this@MainActivity,
request = GetCredentialRequest(
listOf(
GetGoogleIdOption.Builder()
.setFilterByAuthorizedAccounts(false)
.setAutoSelectEnabled(false)
.setServerClientId("secret-id")
.build(),
)
),
).credential
}
setContent {
Text("DEMO")
}
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个带有 DiffUtil 功能的 RecyclerView 适配器。当 DiffUtil 完成其魔法时,我想使用 DataObserver 来通知片段。但是,看起来 DiffUtil 不会调用观察者。
适配器
private val items: MutableList<Message>
private val updater = PublishSubject.create<MutableList<Message>>()
init {
items = ArrayList()
updater
.debounce(500, TimeUnit.MILLISECONDS)
.subscribeOn(Schedulers.computation())
.map { Pair(it, DiffUtil.calculateDiff(DiffUtilCallback(it, items), true)) }
.doOnNext { setItems(it.first) }
.map { it.second }
.observeOn(AndroidSchedulers.mainThread())
.subscribe { diffResult.dispatchUpdatesTo(this) }
}
fun updateData(msgs: MutableList<Message>) = updater.onNext(msgs)
private fun setItems(newItems: MutableList<Message>) {
items.clear()
items.addAll(newItems)
}
Run Code Online (Sandbox Code Playgroud)
分段
adapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
override fun onChanged() {
//is not called
}
})
Run Code Online (Sandbox Code Playgroud)
如何使 AdapterDataObserver …
再会,
我是 Objective-C 和 Xcode IDE 的初学者。我正在尝试在我的 iOS 应用程序中使用 ffmpeg。我克隆了https://github.com/kewlbear/FFmpeg-iOS-build-script并为 arm64 和 x86_64 构建。
当我想构建应用程序时它崩溃了
Ld /Users/nikolajpognerebko/Library/Developer/Xcode/DerivedData/CPP3-eowdhpsbeagmxydsrsscofhtuwtl/Build/Products/Debug-iphonesimulator/CPP3.app/CPP3 normal x86_64
cd /Volumes/sedy/xcode/CPP3
export IPHONEOS_DEPLOYMENT_TARGET=9.1
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.1.sdk -L/Users/nikolajpognerebko/Library/Developer/Xcode/DerivedData/CPP3-eowdhpsbeagmxydsrsscofhtuwtl/Build/Products/Debug-iphonesimulator -L/Volumes/sedy/xcode/CPP3/CPP3/ffmpeg/lib -F/Users/nikolajpognerebko/Library/Developer/Xcode/DerivedData/CPP3-eowdhpsbeagmxydsrsscofhtuwtl/Build/Products/Debug-iphonesimulator -filelist /Users/nikolajpognerebko/Library/Developer/Xcode/DerivedData/CPP3-eowdhpsbeagmxydsrsscofhtuwtl/Build/Intermediates/CPP3.build/Debug-iphonesimulator/CPP3.build/Objects-normal/x86_64/CPP3.LinkFileList -Xlinker -rpath -Xlinker @executable_path/Frameworks -mios-simulator-version-min=9.1 -Xlinker -objc_abi_version -Xlinker 2 -stdlib=libc++ -fobjc-arc -fobjc-link-runtime -lavcodec -lavdevice -lavfilter -lavformat -lavutil -lswresample -lswscale -framework AVFoundation -liconv -lbz2 -Xlinker -dependency_info -Xlinker /Users/nikolajpognerebko/Library/Developer/Xcode/DerivedData/CPP3-eowdhpsbeagmxydsrsscofhtuwtl/Build/Intermediates/CPP3.build/Debug-iphonesimulator/CPP3.build/Objects-normal/x86_64/CPP3_dependency_info.dat -o /Users/nikolajpognerebko/Library/Developer/Xcode/DerivedData/CPP3-eowdhpsbeagmxydsrsscofhtuwtl/Build/Products/Debug-iphonesimulator/CPP3.app/CPP3
Undefined symbols for architecture x86_64:
"av_register_all()", referenced from:
Decoder::Decoder() in ViewController.o
ld: symbol(s) not …
Run Code Online (Sandbox Code Playgroud) 再会,
我有个问题。我需要从 ffmpeg 库获得正确的帧速率..
我尝试使用
pFormatCtx->streams[videoStream]->avg_frame_rate.num
Run Code Online (Sandbox Code Playgroud)
avg_frame_rate 的返回值为 2997。但是当我转储元信息时,我得到:
Input #0, avi, from '/test.avi':
Metadata:
encoder : MEncoder SVN-r33883(20110719-gcc4.5.2)
Duration: 00:49:47.70, start: 0.000000, bitrate: 1294 kb/s
Stream #0:0: Video: mpeg4 (Advanced Simple Profile) (XVID / 0x44495658), yuv420p, 856x480 [SAR 1:1 DAR 107:60], 1090 kb/s, SAR 491520:492521 DAR 8192:4603, 23.98 fps, 23.98 tbr, 23.98 tbn, 23.98 tbc
Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 48000 Hz, stereo, s16p, 192 kb/s
2015-09-20 15:47:02.377 TV3[21607:769601] ready to start audio
Run Code Online (Sandbox Code Playgroud)
采样率为:23.98fps。什么值是正确的以及为什么它们不同?
android ×2
ffmpeg ×2
kotlin ×2
typescript ×2
android-lint ×1
c ×1
git ×1
gradle ×1
gradlew ×1
ios ×1
javascript ×1
objective-c ×1
react-native ×1
reactive ×1
rx-java2 ×1
xcode ×1