我知道 NotificationCenter 已更改,并且我已查找如何使用此链接将其更改为新的实现: Swift 3 上的 NotificationCenter 问题,但我仍然无法让我的工作!我正在使用课堂教科书做我班上的作业,这是我目前的班级:
//
// ViewController.swift
// Persistence
//
// Created by Skyleguy on 10/31/16.
// Copyright © 2016 Skyleguy. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
@IBOutlet var lineFields: [UITextField]!
override func viewDidLoad() {
super.viewDidLoad()
let filePath = self.dataFilePath()
if (FileManager.default.fileExists(atPath: filePath))
{
let array = NSArray(contentsOfFile: filePath) as! [String]
for i in 0 ..< array.count
{
lineFields[i].text = array[i]
}
}
let notificationName = Notification.Name("applicationWillResignActive")
NotificationCenter.default.addObserver(self, selector: #selector(Persistence.applicationWillResignActive(notification: NSNotification)), …Run Code Online (Sandbox Code Playgroud) 我在 firebase 上有一个分数和名称数组,我想接收该数组并将其放入一个数组中。我按照文档所说的去做,最后得到了这个......
databaseRef.child("Leaderboard").queryOrderedByKey().observe(.childChanged, with: {
snapshot in
let value = snapshot.value as? NSDictionary
//Add data to variables
}
Run Code Online (Sandbox Code Playgroud)
但是value被转换为字典,我有两个数组我想接收如何在不混合它们的情况下访问它们?
我的 Firebase 层次结构如下所示
Leaderboard
Scores
50
47
... //Continues
Names
John Doe
BOB
...//Continues
Run Code Online (Sandbox Code Playgroud) 我在许多方向和角度上都有线,我使用绘制了线UIBezierpath。
我需要在这条线的一端画一个箭头。动态地根据给定的点。
编辑2:与杰克答案这是我的代码
let y2 = line.point2Y
let path = UIBezierPath()
path.move(to: CGPoint(x: x1, y: y1))
path.addLine(to: CGPoint(x: x2, y: y2))
path.addArrow(start: CGPoint(x: x1, y: y1), end: CGPoint(x: x2, y: y2), pointerLineLength: ...
path.close()
let shape = CAShapeLayer()
let shapeBorder = CAShapeLayer()
shapeBorder.strokeColor = UIColor.black.cgColor
shapeBorder.lineJoin = kCALineJoinRound
shapeBorder.lineCap = kCALineCapRound
shapeBorder.lineWidth = 10
shapeBorder.addSublayer(shape)
shape.path = path.cgPath
shapeBorder.path = shape.path
shape.lineJoin = kCALineJoinRound
shape.lineCap = kCALineCapRound
shape.lineWidth = shapeBorder.lineWidth-5.0
shape.strokeColor = color
Run Code Online (Sandbox Code Playgroud)
我正在使用更新的Xcode 8.0.如何使用可可豆荚安装alamofire 4.0.我试过这个https://github.com/Alamofire/Alamofire.我转换swift时遇到错误
我正在使用Facebook SDK登录并在我的终端获取数据但无法解决问题我面临与语法相关的挑战
func fetchProfile() {
let parameters = ["fields": "email, first_name, last_name, picture.type(large)"]
FBSDKGraphRequest(graphPath: "me", parameters: parameters).start(completionHandler: { (connection, user, requestError) -> Void in
if requestError != nil {
print(requestError)
return
}
var email = user["email"] as? String
let firstName = user["first_name"] as? String
let lastName = user["last_name"] as? String
self.nameLabel.text = "\(firstName!) \(lastName!)"
var pictureUrl = ""
if let picture = user["picture"] as? NSDictionary, let data = picture["data"] as? NSDictionary, let url = data["url"] as? String {
pictureUrl = …Run Code Online (Sandbox Code Playgroud) 我完成了将我的应用程序迁移到swift3但是此部分不断产生导致问题.
override func viewWillAppear(_ animated: Bool)
{
super.viewWillAppear(animated)
self.navigationController?.setNavigationBarHidden(false, animated: animated)
self.navigationItem.title = artworkTitle
let title = "<center><span style=\"font-size: 17px;font-weight:lighter;font-family:Avenir-Book;\">" + artworkCaption + "</span></center>"
artworkImageView.image = UIImage(named: artworkImagePath)
artworkCaptionView.attributedText = title.html2AttStr
}
Run Code Online (Sandbox Code Playgroud)
重要控制台部件
- [_ SwiftValue unsignedIntegerValue]:发送到实例0x608000243d50的无法识别的选择器,以NSException类型的未捕获异常终止(lldb)
extension String
{
var html2AttStr:NSAttributedString
{
let contents: NSMutableAttributedString?
do {
let attrTextStyle = NSMutableParagraphStyle()
attrTextStyle.alignment = NSTextAlignment.center
contents = try NSMutableAttributedString(data: data(using: String.Encoding.utf8)!, options:[NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: String.Encoding.utf8], documentAttributes: nil)
} catch _ {
contents = nil
}
Run Code Online (Sandbox Code Playgroud)
安慰
0 CoreFoundation 0x000000010b70934b __exceptionPreprocess + …Run Code Online (Sandbox Code Playgroud) 我有以下方法,用swift编写(在swift 3之前).以下是方法
func application(application: UIApplication, didReceiveRemoteNotification launchOptions: [AnyHashable: Any]) -> Void {
Branch.getInstance().handlePushNotification(launchOptions)
}
Run Code Online (Sandbox Code Playgroud)
它给出了错误Use of undeclared type AnyHashable.我怎么能把它转换成快速3.我尝试了以下.
func application(application: UIApplication, didReceiveRemoteNotification launchOptions: [NSObject : AnyObject]) -> Void {
Branch.getInstance().handlePushNotification(launchOptions)
}
Run Code Online (Sandbox Code Playgroud)
它删除了错误,但不知道它的行为方式相同.希望你对此有所帮助.提前.
我在UIView中添加了Label并创建了它的插座,然后在UITapGestureRecognizer的帮助下我添加了功能,但是当我点击或点击标签时.标签文本不会更改.我搜索了类似的问题,我得到的答案也是我写的,但标签文字仍未改变.用Swift 3.0编写的代码.这是我写的代码 -
import UIKit
class testingViewController: UIViewController {
@IBOutlet weak var testLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
let tap:UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(showDatePicker))
tap.numberOfTouchesRequired = 1
tap.numberOfTapsRequired = 1
testLabel.addGestureRecognizer(tap)
testLabel.isUserInteractionEnabled = true// after adding this it worked
// Do any additional setup after loading the view.
}
func showDatePicker(){
print("testing")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, …Run Code Online (Sandbox Code Playgroud) 我正在将我的Swift代码从版本2迁移到3,并且存在以下问题:
参数标签'(count:,repeatedValue :)'与任何可用的重载都不匹配
我的代码
static func getWiFiAddress() -> String? {
var address: String?
var ifaddr: UnsafeMutablePointer<ifaddrs>? = nil
if getifaddrs(&ifaddr) == 0 {
var ptr = ifaddr
while ptr != nil {
defer { ptr = ptr?.pointee.ifa_next }
let interface = ptr?.pointee
let addrFamily = interface?.ifa_addr.pointee.sa_family
if addrFamily == UInt8(AF_INET) || addrFamily == UInt8(AF_INET6) {
let name = String(cString: (interface?.ifa_name)!)
var addr = interface?.ifa_addr.pointee
// issue while assigning to hostname variable
var hostname = [CChar](count: Int(NI_MAXHOST), repeatedValue: 0)
getnameinfo(&addr, socklen_t(interface.ifa_addr.memory.sa_len), …Run Code Online (Sandbox Code Playgroud)