Tag: swift

初始化需要“self”作为参数的Swift属性

我有一个Swift类,我想看起来像这样: class UpdateManager { let timer: NSTimer init() { timer = NSTimer(timeInterval: 600, target: self, selector: "check", userInfo: nil, repeats: true) } func check() { // Do some stuff } } 但是,Swift不喜欢我将self传递给NSTimer初始值设定项的事实。 我在这里打破一些模式? 一个人应该如何完成这样的初始化?

减lessiOS应用程序文件大小

我用Xcode 6.1和swift做了一个非常简单的iPhone应用程序。 我真的很新,ios开发和碰到一个应用程序,最终是134 MB! 当然这是不能接受的。 我有所有屏幕尺寸的背景图像,总计20 MB。 这就是它! 我将这些图像存储在xcassets,因为这是我猜的首选方式。 应用程序不应该超过25 mbs,我想。 我发现我的项目中引用了一些引用。 我删除了这些仍然是我的.app文件是89 mbs! 我究竟做错了什么? 我读了几个线程,但没有什么帮助! 我到现在为止所做的: – reduce the size of all pngs – disable the compress PNG option, as it seems to make the PNGs bigger (lol) – configured the build settings to run the fastest and smallest build – Strip Debug Symbols […]

无法将typesUIViewController的值转换为PatternDetailViewController

我试图将视图控制器向下转换为详细视图控制器,但不能。 我正在使用核心数据(第一次)。 该错误是在prepareForSegue方法和读取:“无法将types'UIViewController'(0x1b81cdc)的值转换为'Patternz.PatternDetailViewController'(0x32488)。(lldb)” 希望能解释为什么它不起作用。 这里是文件。 ViewController.swift import UIKit import CoreData class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { @IBOutlet weak var tableView: UITableView! var patterns : [Pattern] = [] var selectedPattern : Pattern? = nil override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. self.tableView.dataSource = self self.tableView.delegate […]

不能下标的值? 具有typesInt的索引

这是在扩展PFQueryTableViewController的类中,我收到以下错误。 行将只是PFUser 。 为什么我无法施展它? 有没有解决的办法? 错误是: Cannot subscript a value of [AnyObject]? with an index of type Int …这一行: var user2 = self.objects[indexPath.row] as! PFUser

以编程方式创build标签栏控制器后,如何添加导航界面(Swift)

在AppDelegate/didFinishLaunchingWithOptions上创buildTabBarController之后,如何在Swift上以编程方式添加导航接口。 这是我目前的代码: self.window = UIWindow(frame: UIScreen.mainScreen().bounds) let tabBarController = UITabBarController() let purchaseViewController = PurchaseViewController(nibName: "PurchaseViewController", bundle: nil) let financeViewController = FinanceViewController(nibName: "FinanceViewController", bundle: nil) tabBarController.viewControllers = [purchaseViewController, financeViewController] self.window!.rootViewController = tabBarController self.window!.makeKeyAndVisible() 我在看文档。 它有以下准则 – (void)applicationDidFinishLaunching:(UIApplication *)application { self.tabBarController = [[UITabBarController alloc] init]; MyViewController1* vc1 = [[MyViewController1 alloc] init]; MyViewController2* vc2 = [[MyViewController2 alloc] init]; […]

如何在NSUserDefaults中使用存储和使用NSMutableAttributedString

我想创build一个属性string,然后将其存储在NSUserDefaults ,然后再次访问它并将属性string分配给NSUserDefaults 。 我如何去做这件事? 提前致谢。 我不知道很多目标c,所以我不能提及这个答案

私人与fileprivate在Swift3中声明全局variables/常量?

我应该使用private或fileprivate在Swift 3中声明全局variables/常量? 例如 fileprivate let a = 1 fileprivate class SomeClass { fileprivate b = 0 } 要么 private let a = 1 private class someClass { fileprivate b = 0 }

iOS Xcode Swift自动完成破?

我还没有使用过很多Swift,但是来自Objective C,关于Swift的一些东西是PITA来解决我的问题。 在iOS编程中,我们有animateWithDuration:方法,这是UIView的一部分。 所以我试图使用Xcode的自动完成,并开始input: UIView.animateWith 自动完成显示: UIView.animateWithDuration(duration: NSTimeInterval, animations: () -> Void) 然后我选中“duration”字段,然后键入一个数字: UIView.animateWithDuration(0.5, animations: () -> Void) 然后我再次select了animation块,然后像在Objective C中通常那样按下回车,Xcode现在显示: UIView.animateWithDuration(0.5, animations: { () -> Void in code }) 所以然后我最后一次用标签代替我的代码: UIView.animateWithDuration(0.5, animations: { () -> Void in self.customView?.transform = CGAffineTransformMakeTranslation(0.0, 0.0); }) 这是Xcode然后给我的错误: 无法使用types为“(FloatLiteralConvertible,animations:() – > Void)”的参数列表调用“animateWithDuration” 我不明白。 这是Xcode为我生成的自动完成代码,为什么它给我一个错误? 我注意到,如果做一个简单的声明,如: UIView.animateWithDuration(0.5, animations: { () -> […]

迅速ios添加无限滚动分页到uitableview

我不知道如果tableview有任何内置函数来添加无限滚动/分页。 现在我的VC看起来像这样: var data: JSON! = [] override func viewDidLoad() { super.viewDidLoad() //Init start height of cell self.tableView.estimatedRowHeight = 122 self.tableView.rowHeight = UITableViewAutomaticDimension self.tableView.delegate = self self.tableView.dataSource = self savedLoader.startAnimation() //Load first page loadSaved(1) } func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return data.count } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell […]

转换datestringswift

我有这种格式的datestring: 2016-06-20T13:01:46.457+02:00 我需要改变它是这样的: 20/06/2016 以前,我一直使用这个库 – “ SwiftDate来操纵date,但现在不工作。 我也试过类似的东西: let myDate = self.dateNoteDict[indexPath.row]! let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd hh:mm:ss.SSSSxxx" let date = dateFormatter.dateFromString(myDate) print("date -> \(date)") 但它不起作用。 我能怎么做? 提前致谢。