swift-playground

Xcode Playground Timeline empty

ぐ巨炮叔叔 提交于 2019-12-01 19:39:39
问题 I am trying to use the timeline assistant editor for playground in xcode version 7.3.1, it is always empty. Timeline assistant editor I think the error is from xcode, however from search it doesn't look like anyone got the same error so i am confused. 回答1: To display the result of print you need to open the "debug area" by going to menu View > Debug Area > Show Debug Area or click on the button in the lower left part: To display the timeline graph, you could use XCPCaptureValue : import

Why is UInt64 max equal -1 in Swift?

社会主义新天地 提交于 2019-12-01 18:08:07
Using Swift, wether in terminal or playground, when I enter the following on a new line: UInt64.max I get a result value of -1. Is this a bug? Edit: Examples $ xcrun swift Welcome to Swift! Type :help for assistance. 1> UInt64.max / 2 $R1: UInt64 = 9223372036854775807 2> UInt64.max / 2 + 1 $R2: UInt64 = -9223372036854775808 3> UInt64.max $R3: UInt64 = -1 4> println(UInt64.max / 2) 9223372036854775807 5> println(UInt64.max / 2 + 1) 9223372036854775808 6> println(UInt64.max) 18446744073709551615 I think it is a bug of terminal and playground. But, the output of the println is correct

Do instance references really work in Swift?

心已入冬 提交于 2019-12-01 17:59:58
I wrote the Objective-C code first NSMutableString *aStrValue = [NSMutableString stringWithString:@"Hello"]; NSMutableDictionary *aMutDict = [NSMutableDictionary dictionary]; [aMutDict setObject:aStrValue forKey:@"name"]; NSLog(@"Before %@",aMutDict); [aStrValue appendString:@" World"]; NSLog(@"After %@",aMutDict); I got the output as follows 2015-09-17 14:27:21.052 ShareIt[4946:129853] Before { name = Hello; } 2015-09-17 14:27:21.057 ShareIt[4946:129853] After { name = "Hello World"; } Means when I append a string to a Mutable string which is actually referred into a MutableDictionary, the

Do instance references really work in Swift?

徘徊边缘 提交于 2019-12-01 17:37:08
问题 I wrote the Objective-C code first NSMutableString *aStrValue = [NSMutableString stringWithString:@"Hello"]; NSMutableDictionary *aMutDict = [NSMutableDictionary dictionary]; [aMutDict setObject:aStrValue forKey:@"name"]; NSLog(@"Before %@",aMutDict); [aStrValue appendString:@" World"]; NSLog(@"After %@",aMutDict); I got the output as follows 2015-09-17 14:27:21.052 ShareIt[4946:129853] Before { name = Hello; } 2015-09-17 14:27:21.057 ShareIt[4946:129853] After { name = "Hello World"; } Means

Swift Protocol Inheritance & Generic functions

心已入冬 提交于 2019-12-01 17:02:11
Consider the following playground: import Foundation protocol StringInitable { init( string:String ) } class A : StringInitable { var stored:String required init ( string:String ) { stored = string } } class B : A /*, StringInitable */ { var another_stored:String required init ( string:String ) { another_stored = "B-store" super.init(string: string) } } func maker<T:StringInitable>(string:String) -> T { return T(string: string) } let instanceA = A(string: "test-maker-A") let instanceB = B(string: "test-maker-B") let makerA:A = maker("test-maker-A") let makerB:B = maker("test-maker-B") let

Swift Protocol Inheritance & Generic functions

拜拜、爱过 提交于 2019-12-01 16:18:28
问题 Consider the following playground: import Foundation protocol StringInitable { init( string:String ) } class A : StringInitable { var stored:String required init ( string:String ) { stored = string } } class B : A /*, StringInitable */ { var another_stored:String required init ( string:String ) { another_stored = "B-store" super.init(string: string) } } func maker<T:StringInitable>(string:String) -> T { return T(string: string) } let instanceA = A(string: "test-maker-A") let instanceB = B

XCode 6 Playground Measuring Code Performance

淺唱寂寞╮ 提交于 2019-12-01 15:57:41
问题 Is there any quick way of evaluating the performance / runtime of a certain code part written in the new XCode 6 playground? I want to start learning Swift by comparing different coding styles for certain solutions and their impact on the code performance. 回答1: We strongly discourage using playgrounds to measure performance, at least using time as your measure of performance. By far the majority of the time taken during a playground is the logging of results to display in the sidebar; the

Read plist in swift 3 playground

孤街浪徒 提交于 2019-12-01 10:02:03
问题 I have followed loads of questions here but nothing seems to work. I am using Swift3 in a Playground . Running on El Capitan and Xcode 8.1. I have a plist with the root as a Dictionary containing one Int value and two 2D Arrays of Ints. plist Every question I follow does not seem to work the closest I have got is for the playground to not return errors but it seems to be constantly running (the spinning icon never stops). my current code, I believe to be the closest I have achieved. import

How to add a CocoaPod framework to Xcode 8 Playground

跟風遠走 提交于 2019-12-01 06:37:47
I tried to add some pods to the Playground within an Xcode project. Unfortunately, the only scope supported is targets since the update, and link_with is no longer supported. ERROR: [!] Invalid Podfile file: [!] The specification of link_with in the Podfile is now unsupported, please use target blocks instead. When I use target blocks, I get this error: [!] Unable to find a target named MyPlayground , did find Target_1 , Target_2 OR: [!] Unable to find a target named MyPlayground.playground , did find Target_1 , Target_2 Also tried adding it within Target_1 target scope: ERROR [!] Invalid

Animations not working in ios playground

荒凉一梦 提交于 2019-12-01 06:25:52
This is my animation method (PreloaderView.swift) public func performAction(action: PreloaderAction) { let highOpacity = CABasicAnimation.init(keyPath: "opacity") let middleOpacity = CABasicAnimation.init(keyPath: "opacity") let lowOpacity = CABasicAnimation.init(keyPath: "opacity") if action == .PreloaderActionNone { self.thirdShape.removeAllAnimations() self.firstShape.opacity = 0.3; self.secondShape.opacity = 0.5 self.thirdShape.opacity = 1.0 } else if action == .PreloaderActionFailure { UIView.animateWithDuration(2, animations: { self.thirdShape.strokeColor = UIColor.redColor().CGColor })