我有一个结构,我想保存到UserDefaults.这是我的结构
struct Song {
var title: String
var artist: String
}
var songs: [Song] = [
Song(title: "Title 1", artist "Artist 1"),
Song(title: "Title 2", artist "Artist 2"),
Song(title: "Title 3", artist "Artist 3"),
]
Run Code Online (Sandbox Code Playgroud)
在另一个ViewController中,我有一个附加到这个结构的UIButton
@IBAction func likeButtonPressed(_ sender: Any) {
songs.append(Song(title: songs[thisSong].title, artist: songs[thisSong].artist))
}
Run Code Online (Sandbox Code Playgroud)
我想要它,以便每当用户也点击该按钮时,它会将结构保存到UserDefaults,这样每当用户退出应用程序然后打开它时,它就会被保存.我该怎么做?
我想获取我的iPhone连接到的AirPlay或蓝牙设备的名称。我已经通过以下代码实现了这一点...
let currentRoute = AVAudioSession.sharedInstance().currentRoute
for output in currentRoute.outputs {
print("Connected port name: \(output.portName)")
}
Run Code Online (Sandbox Code Playgroud)
但是,每当我的iPhone连接到HomePod或Apple TV等AirPlay设备时,portName返回的都是"Speaker"。我想获得HomePod或Apple TV的名称。但是,无论何时我的设备连接到蓝牙,它都可以工作。例如,每当我连接到AirPods时,"Jacob's AirPods"都会返回该名称。每当我连接到另一个蓝牙设备时,都会返回正确的名称。
我相信获得AirPlay设备的名称应该是可能的,因为Apple在其Apple Music应用和整个系统中都可以使用它。像吼叫...
有什么建议么?
所以我有这个想法.请记住,我对此并不了解,所以如果这太雄心勃勃,我很抱歉.基本上,我想在连接到显示器的Raspberry Pi上运行Swift"app".我知道如何编写iOS应用程序代码,我在App Store上有一些,但这是一个我一直在考虑的全新项目.我将如何实现这一目标?我在网上查看了教程,但没有一个展示如何在监视器上运行实际的可视化Swift代码.他们中的大多数都在展示如何打开LED灯或类似的东西.我不想那样做.我想运行Swift代码(最好是通过Xcode)和故事板和UIViewControllers以及连接到监视器的Raspberry Pi上的所有东西.有没有人知道的想法或教程?请记住,我是Raspberry Pi的新手.我唯一的经验是使用Xcode编写iOS应用程序.
我正在尝试执行(看似)简单的任务,将本机 AdMob 广告集成到我在 Swift 上运行的 iOS 应用程序中。让我首先向您展示我的故事板和集成代码,然后我们将继续讨论我尝试修复的问题。
设置:故事板和代码
在我的 App Delegate 中,我将 Firebase 配置为 Google 移动广告...
import Firebase
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
FirebaseApp.configure()
GADMobileAds.configure(withApplicationID: "ca-app-pub-8482280186158418~7106629637")
GADMobileAds.sharedInstance().start(completionHandler: nil)
}
}
Run Code Online (Sandbox Code Playgroud)
我还将我的添加GADApplicationIdentifier到我的 Info.plist。在我的故事板中,我有一个ViewController包含 a 的UICollectionViewCell包含 aGADUnifiedNativeAdView并且本机元素通过插座链接。
在我的 ViewController 的 viewDidLoad 中,我加载了 5 个原生广告。
override func viewDidLoad() {
super.viewDidLoad()
// Load Ads
let adUnitID = …Run Code Online (Sandbox Code Playgroud) 是的我知道。您无法更改UIAlertController. 我不想改变UIAlertController本身的背景,我想改变视图背景的色调。你知道透明的黑色是怎样的吗?我想将该颜色更改为清除。我该怎么做?
感谢您抽时间阅读.我对如何使用YouTube API插入评论感到困惑.我是使用API的新手,所以我不太清楚他们在文档中要做的事情.
我已经验证使用用户谷歌登录功能适用于iOS与范围
"https://www.googleapis.com/auth/youtube.force-ssl"
Run Code Online (Sandbox Code Playgroud)
这是插入评论所必需的.但是现在,我必须插入评论并且(就像我说的那样)我不明白该怎么做,因为我必须在请求体中提供资源.我正在使用Alamofire作为请求,而Swift 4作为我的语言.如果有人能帮助我,我将非常感激.
我正在我的 iPhone/iPad 应用程序中实现一项功能,当 iPhone 连接到外部显示器时,iPhone 充当控制器,外部显示器显示非交互式视图。我正在使用 SwiftUI。
\n我的应用程序实际上与 Apple 文档中的概念非常相似。iPhone/iPad 将始终用作控制器,而外部显示器将始终显示内容,就 Apple 而言,是游戏。因此,将游戏镜像到 QuickTime 或 StreamLabs 时,需要镜像实际游戏,而不是控制器。这是我在 Apple 文档中讨论的示例,以便您可以直观地看到它。
\n\n以下是我SceneDelegate按照 Apple文档在 中实现它的方法。
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {\n guard let windowScene = scene as? UIWindowScene else { return }\n if session.role == .windowApplication {\n let window = UIWindow(windowScene: windowScene)\n window.rootViewController = UIHostingController(rootView: ContentView())\n window.makeKeyAndVisible()\n }\n \n if session.role == .windowExternalDisplayNonInteractive {\n let window …Run Code Online (Sandbox Code Playgroud) 我正在使用Swift制作应用程序,而我正在使用Firebase Firestore.Firestore是一个数据库,它包含一些我放入的字符串UILabel.我的一些叮咬,我使用新的行命令(或\n).所以我的一些字符串看起来像这样:
"This is line one\nThis is line two\nThis is line three"
Run Code Online (Sandbox Code Playgroud)
但是,无论何时检索到该字符串,它都是addetoto UILabel并且看起来像这样......
这是第一行\n这是第二行\n这是第三行
......应该是这样......
这是第一行
这是第二行
这是第三行
我假设这\n不适用于来自数据库的字符串?我试过双重逃避\\n.有人有解决方法吗?
这是我正在使用的代码......
database.collection("songs").whereField("storyTitle", isEqualTo: "This is the story header").getDocuments { (snapshot, error) in
for document in (snapshot?.documents)! {
self.storyBodyLabel.text = (document.data()["storyBody"] as? String)!
}
}
Run Code Online (Sandbox Code Playgroud) 我需要将Alamofire添加到我的主要iOS应用和iOS Today Extension中。Alamofire只是我的iOS应用目标,因此效果很好!但是现在,我正在尝试将Alamofire添加到我今天的扩展中。这是我的Podfile
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target 'The Main iOS App' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
pod 'Canvas'
pod 'Firebase/Core’
pod 'Firebase/Messaging’
pod 'Alamofire', '~> 4.4'
# Pods for The Main iOS App
end
target 'Today' do
# Comment the next line if you're not using Swift and don't want to use …Run Code Online (Sandbox Code Playgroud) 我想创建一个 Int 数组,我可以将其附加到并将被保存到,UserDefaults以便下次用户打开应用程序时,该数组将被保存。所以,我知道如何创建一个UserDefaults数组...
var intArray = UserDefaults.standard.array(forKey: "intArray") as! [Int]
Run Code Online (Sandbox Code Playgroud)
我知道如何将数组设置为已经存在的数组:
var array = [2, 6, 34, 4, 9]
UserDefaults.standard.set(array, forKey: "intsArray")
Run Code Online (Sandbox Code Playgroud)
但是,我需要数组为空,然后用户将 Int 添加到数组中。谢谢你的帮助!