Just learning Swift and I noticed that Apple's example code on the Swift homepage does not compile in playground! I mean really, am I missing something?https://developer.apple.com/swift/extension String { var banana : String { let shortName = String(dropFirst(characters)) return (self) (self) Bo B(shortName) Banana Fana Fo F(shortName) } } let bananaName = Jimmy.bananaI changed line 03 to: { let shortName = String(dropFirst(self))This seems to work. I tried to find feedback and let them know, but there seems to be no place for developers to provide simple feedback.
Search results for
Swift 6
49,200 results found
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
You have to create these connections in InterfaceBuilder. The following text gives a good explanation (examples in ObjectiveC but works in Swift the same):https://developer.apple.com/library/prerelease/ios/recipes/xcode_help-IB_connections/chapters/AboutConnectingObjectstoCode.htmlAnd no fear: Cocoa is a big framework and the needed information is sometimes a little hard to find 🙂
Topic:
Programming Languages
SubTopic:
Swift
Tags:
Thank you.I probably resolved this problem.'User Defined Runtime Attributes' was good clue for me.I tried the following code by referencing https://www.weheartswift.com/make-awesome-ui-components-ios-8-using-swift-xcode-6/@IBDesignableclass BorderView: UIView { @IBInspectable var cornerRadius: CGFloat = 5 { didSet { layer.cornerRadius = cornerRadius layer.masksToBounds = cornerRadius > 0 } } @IBInspectable var borderWidth: CGFloat = 1 { didSet { layer.borderWidth = borderWidth } } @IBInspectable var borderColor: UIColor? = UIColor.blueColor() { didSet { layer.borderColor = borderColor?.CGColor } }}if i tried above file on another project,it ran correctly.if i couldn't run correctly another project,i would write it.Thank you.
Topic:
UI Frameworks
SubTopic:
UIKit
Tags:
I have just installed iOS 9 on my iPhone 6 Plus and when it started up it wiped my apple watch and I had to set it up again.After setting my apple watch up again I am missing the Activity Data for the last 48 hours, but when i look at the activity app on my phone the steps and what not are there but the rings for the last 2 days are both empty
This example requires Swift2. The characters-property of String is new and didn't exist in Swift 1.2. So you have to use Xcode7 beta for it.
Topic:
Programming Languages
SubTopic:
Swift
Tags:
Hello everyone,Has anyone figured out a way to subclass NSNotification using Swift? I've done this in the past with Objective-C, but haven't figured out how to accomplish this with the rules for initializers in Swift. I realize there are alternatives to subclassing, but I'd really like to figure out how to do this. Here is a simplified version of what I'm attempting to do:class MyNotification: NSNotification { var someCustomData: String = override var name: String { return } override var object: AnyObject? { return nil } override var userInfo: [NSObject: AnyObject]? { return nil } required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) } init(someCustomData: String) { // Compiler wants me to call super.init, but this causes // issues since NSNotification is a class cluster. } }If I try calling super.init or using one of the NSNotification initializers when I instantiate an instance of MyNotification, I get this error:*** initialization method -initWithName:object:userInfo: ca
Have you ever done a iOS beta before? These are very much to be expected.1. The claims they make will be what they are expecting for the final release2. iOS 6 beta was significantly worse.3. If you think this is bad... just wait, in the past the betas have gone from bad battery life to good, to bad again. They are working out the issues, you cannot expect this to work like a final product... because well, it is far from it.
Topic:
App & System Services
SubTopic:
Core OS
Tags:
Have tried 5 or 6 times now it install the beta package for 1474 on two diffrent computers. Each time the install freezes after about 10% and itunes pops and error code 14. I have tried diffrent cables and ports with no luck so far. I have tried redownloading the package to insure it wasnt corrupted but still no luck. It restores to 8.3 from both computers without trouble. I am unsure what to do from here. Has anyone else come across this and resolved it? Any suggestions as to what to try next? Your help is appreciated.
Apparently it is only supported on 6, 6+ and latest ipad (GPUFamily2) and adds on the features/limits of v1:http://f.cl.ly/items/2U341j1B1o1V0W3K253x/Bildschirmfoto%202015-06-10%20um%2000.48.20.pnghttp://f.cl.ly/items/0m421K2e3F2Q2y0g3k0Z/Bildschirmfoto%202015-06-10%20um%2000.58.33.pngAlso some new uniform buffer updating and a couple other things are new.
Topic:
Graphics & Games
SubTopic:
General
Tags:
how to convert a textfield to a int in swift 2
I think I've got my Connectivity stuff set up properly, was going off the Lister sample app. But, every time I try to send stuff via WCSession, it fails. Here's the code:// iOS App, in my ViewController override func viewDidLoad() { super.viewDidLoad() if WCSession.isSupported() { WCSession.defaultSession().delegate = self WCSession.defaultSession().activateSession() } } func session(session: WCSession, didReceiveMessage message: [String : AnyObject]) { let msg = message[message] as! String print(Got message! (msg)) } // -------------- // WatchKit Extension - WKInterfaceController subclass @IBAction func buttonTapped() { let session = WCSession.defaultSession() print(Session is reachable: (session.reachable)) // this is false let msg = [message: derp derp derp] session.sendMessage(msg, replyHandler: { reply in print(Got reply: (reply)) }, errorHandler: { error in print(error: (error)) }) }The error in the errorHandler reads Error Domain=WCErrorDomain Code=7004 The operation couldn’t be completed. (WCErrorDoma
On iOS 8, this code (Swift) worked:let shaderString = void main() + { + gl_FragColor = SKDefaultShading().bgra; + } let shader = SKShader(source: shaderString)Now on iOS 9, with Metal under the covers, I get this error message:2015-06-09 18:36:39.497 TestVideoCam[550:63920] Jet: Error Domain=MTLLibraryErrorDomain Code=3 Compilation failed: program_source:6:321: error: use of undeclared identifier 'SKDefaultShading' fragment float4 SKShader_FragFunc( texture2d<float> u_texture [[texture(0)]], const device float *u_time [[buffer(0)]], const device float2 *u_sprite_size [[buffer(1)]], const device float *u_path_length [[buffer(2)]], SKShader_VertexOut interpolated [[stage_in]]){return SKDefaultShading().bgra;} ^ UserInfo=0x156e50c10 {NSLocalizedDescription=Compilation failed: program_source:6:321: error: use of undeclared identifier 'SKDefaultShading' fragment float4 SKShader_FragFunc( texture2d<float> u_texture [[texture(0)]], const device float *u_time [[buffer(0)]], con
For Xcode 6, if nothing is being output, you might want to see if there's a syntax error preventing compilation and execution.For Xcode 7, make sure you've opened the debug area vs the assistant
Topic:
Developer Tools & Services
SubTopic:
Xcode
Tags:
Updated an app to iOS 9 / Swift 2 / watchOS 2 and since then, Xcode claims it can't find my embedded framework when building the watchOS extension. It has no issues finding it for my iOS app and the build settings look ok - the framework is showing as a dependency... but yeah, no dice. Tried cleaning and nuking Derived Data.Any ideas?
Is there a way to get the type of a given variable or constant ?I know how to check to a specific class, but not how to get the underlying type