随着Swift的推出,我一直试图让我的头脑围绕新的语言 我是一个iOS开发人员,将在应用程序中使用types,如NSString, NSInteger, NSDictionary 。 我注意到在Apple的“The Swift Programming Language”电子书中,他们使用Swifttypes的String, Int, Dictionary 我注意到Swifttypes没有(或不同地命名)一些基础types的function。 例如NSString有一个length属性。 但我一直无法find一个类似的Swift String 。 我想知道,对于iOS应用程序,我还应该使用基础types?
迅速有声明吗? 如果我做了以下 var testVar = "hello" var result = 0 switch(testVal) { case "one": result = 1 case "two": result = 1 default: result = 3 } 是否有可能为“一”和“两”情况执行相同的代码?
我需要创build一个可以将int,long,double等types转换为string的格式的string。 使用Obj-C,我可以通过下面的方法。 NSString *str = [NSString stringWithFormat:@"%d , %f, %ld, %@", INT_VALUE, FLOAT_VALUE, DOUBLE_VALUE, STRING_VALUE]; 如何做到与swift相同?
如何在Swift中访问命令行应用程序的命令行参数?
我在界面生成器中创build了一个自定义的UICollectionViewCell,将它绑定到类的视图上,然后当我想使用string并设置一个string到标签上时,标签有一个零值。 override func viewDidLoad() { super.viewDidLoad() // Register cell classes self.collectionView.registerClass(LeftMenuCollectionViewCell.self, forCellWithReuseIdentifier: "ls") } override func collectionView(collectionView: UICollectionView!, cellForItemAtIndexPath indexPath: NSIndexPath!) -> UICollectionViewCell! { var cell: LeftMenuCollectionViewCell cell = collectionView.dequeueReusableCellWithReuseIdentifier("ls", forIndexPath: indexPath) as LeftMenuCollectionViewCell println(cell.label) // <- this is nil, why?? cell.label.text = "asd" return cell } 和子types的单元格: class LeftMenuCollectionViewCell: UICollectionViewCell { @IBOutlet weak var […]
状态栏中的背景文字仍然是黑色的。 如何将颜色更改为白色? // io8, swift, Xcode 6.0.1 override func viewDidLoad() { super.viewDidLoad() self.navigationController?.navigationBar.barTintColor = UIColor.blackColor() self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.orangeColor()] }
我试图添加一个UIPopoverView到我的Swift iOS 8应用程序,但我无法访问PopoverContentSize属性,因为弹窗没有显示正确的形状。 我的代码: var popover: UIPopoverController? = nil func addCategory() { var newCategory = storyboard.instantiateViewControllerWithIdentifier("NewCategory") as UIViewController var nav = UINavigationController(rootViewController: newCategory) popover = UIPopoverController(contentViewController: nav) popover!.setPopoverContentSize(CGSizeMake(550, 600), animated: true) popover!.delegate = self popover!.presentPopoverFromBarButtonItem(self.navigationItem.rightBarButtonItem, permittedArrowDirections: UIPopoverArrowDirection.Any, animated: true) } 输出: 当我通过UIPopoverPresentationController做同样的事情时,我仍然没有完成。 这是我的代码: func addCategory() { var popoverContent = self.storyboard.instantiateViewControllerWithIdentifier("NewCategory") as UIViewController var nav = […]
我读了Xcode 6中的新function 。 文章介绍了一些关于Xcode 6的新特性,它说: 命令行 Xcode的debugging器包含Swift语言的交互式版本,称为REPL(Read-Eval-Print-Loop)。 使用Swift语法评估并与正在运行的应用程序交互,或在类似脚本的环境中编写新代码。 REPL可以从XLD控制台的LLDB内部或terminal上获得。 我想知道如何获得REPL?
有人可以请教我最简单的方法来更改UITableView节头中的文本的字体大小? 我使用以下方法实现了部分标题: – (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section 然后,我明白如何使用这种方法成功更改节头高度: – (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section 我有使用此方法填充的UITableView单元格: – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 然而,我坚持如何实际增加节标题文本的字体大小或字体样式? 有人可以协助吗? 谢谢。
我有简单的字典,这是定义如下: var dict : NSDictionary = [ 1 : "abc", 2 : "cde"] 但是后来我想添加一些元素到这个字典中,这个元素是3 : "efg" 但我不知道如何执行这个行动,我在互联网上search了很多,但没有什么可以帮助我。 有谁可以告诉我如何追加3 : "efg"到这个现有的字典?