Search results for

Swift 6

49,210 results found

Post

Replies

Boosts

Views

Activity

Printing optional strings in Swift
It seems that (in Swift 2, at least), printing optionals no longer prints a tidy result (nil or the value of the string), but rather printsString: Optional(Hello, playground)Is there no succinct way of printing the contents of an optional as either nil or whatever the string value is?
0
0
108
Jun ’15
WKWebsiteDataStore
Hi, I'm playing around with WKWebsiteDataStore, and throwing an exception each time I attempt to ask for the default store using:[WKWebsiteDataStore WKWebsiteDataStore];Stack Trace:2015-06-10 14:26:35.264 iOS9Sample[34994:293382] +[WKWebsiteDataStore WKWebsiteDataStore]: unrecognized selector sent to class 0x2447458 2015-06-10 14:26:35.266 iOS9Sample[34994:293382] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[WKWebsiteDataStore WKWebsiteDataStore]: unrecognized selector sent to class 0x2447458' *** First throw call stack: ( 0 CoreFoundation 0x00aa4c54 __exceptionPreprocess + 180 1 libobjc.A.dylib 0x00564e26 objc_exception_throw + 50 2 CoreFoundation 0x00aadaa3 +[NSObject(NSObject) doesNotRecognizeSelector:] + 275 3 CoreFoundation 0x009eb32d ___forwarding___ + 1037 4 CoreFoundation 0x009eaefe _CF_forwarding_prep_0 + 14 5 iOS9Sample 0x0009aee1 -[ViewController webView:didFinishNavigation:] + 113 6 WebKit 0x021bb1fd _ZN6WebKit15NavigationState16NavigationClient19
1
0
754
Jun ’15
Xcode 7 crashes on startup
I've downloaded the .dmg, copied to Applications, waited for the verification - said 'open' once the verification is done then Xcode crashes. I'm running 10.10.3 which I think should work. I've tried uninstalling, re-downloading and re-doing the process with not luck. Has anyone else encountered this problem? Thanks.This is the error:Process: Xcode [396]Path: /Applications/Xcode-beta.app/Contents/MacOS/XcodeIdentifier: com.apple.dt.XcodeVersion: 7.0 (8123.26)Build Info: IDEFrameworks-8123026000000000~7Code Type: X86-64 (Native)Parent Process: ??? [1]Responsible: Xcode [396]User ID: 501Date/Time: 2015-06-10 17:25:29.684 -0400OS Version: Mac OS X 10.10.3 (14D136)Report Version: 11Anonymous UUID: A4A041F0-414B-EB94-4B70-43B0C8715464Time Awake Since Boot: 320 secondsCrashed Thread: 0 Dispatch queue: com.apple.main-threadException Type: EXC_CRASH (SIGABRT)Exception Codes: 0x0000000000000000, 0x0000000000000000Application Specific Information:ProductBuildVersion: 7A120fASSERTION FAILURE in /Library/Caches/com.apple
6
0
2.0k
Jun ’15
IOS App Install Fail Over The Air
Hi, I'm using Xcode6 and created a test app for ipad. It compiles and runs fine in simulator. My next step is to distribute it using adhoc distribution mechanism. Here is what I've done1. Using Keychain Access to create a public/private key pair.2. Load it up into Developer Center to create a certificate, then download it.3. Add my ipad UUID under Devices.4. Create a adhoc provisioning profile by including my ipad in it, I only have one device in Member Center. Let's call the provision MyProv.5. Run the .cer file by double clicking it.6. Download the .mobileprovision file from Member Center to desktop. Then double click it.Now, in Xcode, under Build Setting, I change Provisioning Profile Debug and Release entry to point to MyProv, then run Product->Archive. When archiving the app, Xcode as me if I want to use my key created in step 1 above to sign the bundle. I allow it. I also choose to Save for ad hoc distribution when asked. In the summary page, I can see the Provisioning Profile column shows '
2
0
1.7k
Jun ’15
ErrorType
Hello!I'm curious about the best ways to handle errors that occur in asynchronous callbacks in Swift 2. It seems that returning an NSError (or ErrorType) via a callback argument is still a workable option, but this does not jive well with the new try/throw/catch/ErrorType syntax.What is the correct way to throw an asyncronous error with the new syntax?Here's a complete example to demonstrate:MyPlayground.playgroundimport Foundation import XCPlayground enum Either<L,R> { case Left(L); case Right(R) } enum MyError : ErrorType { case Failure } let succeed = arc4random_uniform(2) > 0 func performWorkSync_happy() throws -> String { // This is great! print(Sync start) if !succeed { throw MyError.Failure } return Hello, World! } func performWorkAsync_sad(callback : Either<String, MyError> / throws */ -> Void) -> Void { print(Async start) dispatch_async(dispatch_get_main_queue()) { () -> Void in // TODO: This isn't quite right.... /* if !succeed { throw Example.Failed } else { retu
3
0
2.7k
Jun ’15
optional protocols
I'm kind of dissapointed with the lack of optional protocols for native Swift types still in 2.0. I am happy to see the workaround of declaring default implementations through protocol extensions, but this seems like a workaround rather then a solution. The language natively supports optional protocols, except they have to be delared with the @objc keyword, which rules out using classes/structs/enums that I define in in the function declaration. I tried using the @nonobjc keyword inside the protocol, but only ended up with a compiler error (which is what I was expecting anyway). I'm sure there is a valid reason not to implement them in the language, I just don't know what it is, and can't for the life of me figure it out on my own. Especially as all the language support for working with them seems to be in place.AndrewPS, In case you're wondering, yes I filed a bug report on this a long time ago.
1
0
265
Jun ’15
How to ignore errors?
First of all, let me just go out and say that this new error handling system in Swift is a huge, huge improvement. However, this is one case that I'm unsure about, which is when you legitimately care about errors. However, sometimes you don't care about the specific error, but you just want to know if something succeeds or not. A good example is checking the availability of a file, where you just want to know if it's reachable and don't want to bomb out if it's not. In Objective-C, this would be done with one line of code, simply by passing NULL for the error parameter:BOOL isReachable = [someURL.checkResourceIsReachableAndReturnError: NULL];However, in Swift 2, the best way I can see to do this is:let someURL = ... let isReachable: Bool do { try someURL.checkResourceIsReachableAndReturnError() isReachable = true } catch { isReachable = false }This seems somewhat verbose and awkward. Is there any more elegant way just to check if a file is reachable without treating the result as an error?
7
0
3.7k
Jun ’15
Reply to How to ignore errors?
In the Swift 2 Prerelease for the Swift book, it states:“There are some cases in which you know a throwing function or method won’t, in fact, throw an error at run time. In these cases, you can call the throwing function or method in a forced-try expression, written, try!, instead of a regular try expression.Calling a throwing function or method with try! disables error propagation and wraps the call in a run-time assertion that no error will be thrown. If an error actually is thrown, you’ll get a runtime error.”https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/ErrorHandling.html#//apple_ref/doc/uid/TP40014097-CH42-ID508(there is no way to deep-link to the relevant section but it's the second from last, Disabling Error Propagation.)If you have a chance to watch the video posted on the developer site from the What's new in Swift session, it's well worth it. I think that's where I saw this.
Topic: Programming Languages SubTopic: Swift Tags:
Jun ’15
Reply to iOS 9 Beta battery life
I too have been experiencing the same very fast battery drain that you are all talking about. I have an iPhone 6 16GB. I just recently re-install iOS 9 right over my previous iOS 9. Since doing this my battery life experience has greatly improved. I can't exactly say that things are back to normal but very much better than before I re-updated. I did try re-installing iOS 8.3, restoring from backup and then upgrading to iOS 9. 1st and 2nd time same results, battery life out of control. Now that I just updated right on top of iOS 9 and things have greatly improved. If things change I will re-post. Good Luck!!!
Topic: App & System Services SubTopic: Core OS Tags:
Jun ’15
Altimeter and required device capabilities
We're developing an app that requires that the device has altimeter present. Currently there is no way of targeting such devices with required device capabilities as iPhone 5S supports everything 6 & 6 Plus does (and it would be wrong anyway). Sure we could test it in code, but it would be unpleasant for the user to purchase the app only to discover that the key feature does not work on her device.Is there a plan to add this capability to the requirements or is there something else we haven't thought about?
1
0
1k
Jun ’15