我有这个结构:
struct message {
var id: String = "0"
var text: String = ""
var date: Date!
var status: String = ""
}
Run Code Online (Sandbox Code Playgroud)
我必须从dbase加载这个结构,它String也以格式导出date.所以我写这段代码转换String为Date类型:
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
dateFormatter.timeZone = NSTimeZone(abbreviation: "UTC") as TimeZone!
let dataDate = dateFormatter.date(from: elemMessage["date"] as! String)!
Run Code Online (Sandbox Code Playgroud)
我将它加载到结构中:
message(id: elemMessage["id"] as! String, text: elemMessage["text"] as! String, date: dataDate as! Date, status: elemMessage["status"] as! String)
Run Code Online (Sandbox Code Playgroud)
但是我有这个警告:"从不Date相关的类型转换Date总是失败"
因此,如果我运行应用程序,它将失败.
我怎样才能解决这个问题,date结构中的var必须是 …
我的应用程序使用谷歌+登录和我的appdelegate.swift我有:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
var configureError: NSError?
GGLContext.sharedInstance().configureWithError(&configureError)
assert(configureError == nil, "Error configuring Google services: \(configureError)")
GIDSignIn.sharedInstance().delegate = self
return true
}
func application(application: UIApplication,
openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
return GIDSignIn.sharedInstance().handleURL(url,
sourceApplication: sourceApplication,
annotation: annotation)
}
Run Code Online (Sandbox Code Playgroud)
现在我想插入facebook登录,但我必须在appdelegate.swift中添加此代码:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions) …Run Code Online (Sandbox Code Playgroud) 我有一个仅在rtsp:// ipaddress/live上发送流媒体视频的IpCam.我的软件只接受HTTP上的流媒体视频.
所以我可以使用FFMPEG将流媒体从RTSP转换为HTTP.
我在Windows 7上安装了FFMPEG,我尝试了将RTSP转换为视频文件的示例:ffmpeg -i rtsp://192.168.0.43:1256 -r 15 C:/output/video.mp4它可以工作.
可以帮我转换RTSP到HTTP流(我使用Windows 7 SO).
谢谢.
我使用以下代码发送带有位置的JSQMessage,我没有任何错误,但消息没有在视图中显示.
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
var latestLocation: CLLocation = locations[locations.count-1]
let loc: JSQLocationMediaItem = JSQLocationMediaItem(location: latestLocation)
loc.appliesMediaViewMaskAsOutgoing = true
let locmessage: JSQMessage = JSQMessage(senderId: self.senderId, senderDisplayName: self.senderDisplayName, date: NSDate(), media: loc)
messages.append(locmessage)
self.finishSendingMessageAnimated(true)
}
Run Code Online (Sandbox Code Playgroud)
和
override func collectionView(collectionView: JSQMessagesCollectionView!, messageBubbleImageDataForItemAtIndexPath indexPath: NSIndexPath!) -> JSQMessageBubbleImageDataSource! {
let factory = JSQMessagesBubbleImageFactory()
if messages[indexPath.row].senderId == senderId {
return factory.outgoingMessagesBubbleImageWithColor(UIColor.lightGrayColor())
} else {
return factory.incomingMessagesBubbleImageWithColor(UIColor.greenColor())
}
}
Run Code Online (Sandbox Code Playgroud)
其他类型的消息(照片和视频)没问题.
谁能帮我.
谢谢.
我需要发布一个 http 请求以登录视图(SwiftUI),我的代码遵循我在 HttpAuth.swift 中的代码:
import Foundation
import Combine
struct ServerMessage: Decodable {
let res, message: String
}
class HttpAuth: ObservableObject {
let objectWillChange = PassthroughSubject<HttpAuth, Never>()
var authenticated = false {
didSet {
objectWillChange.send(self)
}
}
func postAuth(username: String, password: String) {
guard let url = URL(string: "http://mysite/loginswift.php") else { return }
let body: [String: String] = ["username": username, "password": password]
let finalBody = try! JSONSerialization.data(withJSONObject: body)
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.httpBody = finalBody
request.setValue("application/json", …Run Code Online (Sandbox Code Playgroud)