草庐IT

swift_FORCE_LOAD

全部标签

swift - 从零运行时开销的字符串文字初始化 CChar 或 UInt8 (Swift)

如何在Swift中使用字符串文字初始化CChar或UInt8?extensionUInt8:ExtendedGraphemeClusterLiteralConvertible{publicstaticfuncconvertFromExtendedGraphemeClusterLiteral(value:String)->UInt8{letnum=value.unicodeScalars[value.unicodeScalars.startIndex]returnUInt8(num.value)}}leta:UInt8="A"println(a)这是我的尝试,但我猜它是在运行时执行的。如

ios - 如何在 SpriteKit 和 SceneKit 中暂停游戏 - SWIFT

我想通过触摸按钮来暂停我的游戏,但我无法让它工作。我试过这个:pause=SKSpriteNode(imageNamed:"pause.png")pause.size=CGSizeMake(30,30)pause.position=CGPointMake(30,30)self.addChild(pause)我正在尝试调用这样的函数:functouchesBegin(touches:NSSet!,withEventevent:UIEvent!){fortouch:AnyObjectintouches{letlocation=touch.locationInNode(self)ifself

ios - 在 Swift 中遍历 View Controller 层次结构

我想遍历Swift中的ViewController层次结构并找到一个特定的类。这是代码:extensionUIViewController{functraverseAndFindClass()->UIViewController?{varparentController=self.parentViewControlleras?T?^||//Error:Couldnotfindauser-definedconversionfromtype'UIViewController?'totype'UIViewController'while(parentController!=nil){pare

swift - ( swift )错误 : can not invoke '>' with an argument list of type '(UInt32, @lvalue UInt32)'

classViewController:UIViewController{@IBOutletweakvarinputField:UITextField!@IBOutletweakvaroutput:UITextView!varguesses:UInt=0varnumber:UInt32=0vargameOver=falseletMAX_GUESSES:UInt=8@IBActionfuncguess(sender:UIButton){varpossibleGuess:Int?=inputField.text.toInt()ifletguess=possibleGuess{//possi

Swift curried 函数的行为与扩展版本不同

我在Swift中有一个柯里化(Currying)函数:funccounter(varval:Int)()->(){val++println(val)}根据thisanswer它应该等同于:funccounter(varval:Int)->(()->()){funccurryFunc(){val++println(val)}returncurryFunc}但是,当我运行以下代码时:letx=counter(3)x()x()对于第一个,我得到4,4;而对于第二个,我得到4、5。我使用的是Xcode6.0.1版本。 最佳答案 不同之处在于

swift - 什么时候使用 obj!.attr 和 obj?.attr?

如果obj不存在obj?生成一个nil所以obj?.attr也是。如果obj为nil,则obj!.attr崩溃。但是如果我确定obj在代码的某个点总是存在,那么对我来说似乎使用哪个是独立的。我对吗?您使用什么编码风格? 最佳答案 在我看来,如果你真的确定obj存在,你可以使用!或者?任何一个。它们对现有对象产生相同的效果。唯一的问题是编译器:有时使用!而不是?,有时不是。无论如何,如果您想进一步阅读,请给Apple的免费书籍“TheSwiftProgrammingLanguage”一个机会:那里对这些内容有很好的解释!

ios - 在 Swift 中更改现有按钮的操作

我想将现有按钮的操作更改为我的MainTableViewController中的功能。如果我以编程方式创建按钮,这不是问题-但使用Storyboard-Editor中的现有按钮将不会调用该方法。知道这里出了什么问题吗?classSignatureTableViewCell:UITableViewCell{@IBOutletweakvarsignatureButton:UIButton!varformVC:FormTableViewController!overridefuncawakeFromNib(){super.awakeFromNib()//Initializationcode}

ios - 如何将此 objective-c 转换为 swift

NSURL*url=[NSURLURLWithString:@"http://iminichrispy.com/Xcode/TextFromWeb.txt"];NSString*content=[NSStringstringWithContentsOfURL:urlencoding:NSStringEncodingConversionAllowLossyerror:nil];label.text=content;我试过以下方法varurl:NSURL=NSURL(string:"http://iminichrispy.com/Xcode/TextFromWeb.txt")varcont

iOS Swift UICollectionView registerNib 可重用 View 不起作用

我正在尝试使用UICollectionViewController创建一个类似iCalendar的对象。现在我正在尝试添加可重复使用的View作为每一天的列标题。我制作了一个Storyboard并添加了一个链接到此类的UICollectionViewController:importUIKitclassWeekViewController:UICollectionViewController,UICollectionViewDelegate{letdataSource=WeekViewDataSource()letweekLayout=WeekViewLayout()overridef

swift - 如何在函数调用后读取代码块?

我是swift的新手,我需要阅读以下代码的帮助。函数调用“self.table.update(completedItem)”之后的代码块的含义是什么{...}代码块第一行的(result,error)是什么意思:self.table!.update(completedItem){(结果,错误)在//...来代码完整代码:overridefunctableView(tableView:UITableView,commitEditingStyleeditingStyle:UITableViewCellEditingStyle,forRowAtIndexPathindexPath:NSInd