|
Pattern matching uses the ~= operator. It's buried in the Language Reference under Patterns. However the default implementation should succeed if the two objects are the same type and implement the == operator. You need: code:
Simulated fucked around with this message at 06:01 on Jun 28, 2014 |
# ¿ Jun 28, 2014 05:58 |
|
|
# ¿ May 14, 2024 09:37 |
|
rjmccall or any of you other Apple folks, if you get a chance can you review my scribblings about interop in Swift? Specifically: Unsafepointer<T>, including alloc and Unmanaged<T>. There is almost no documentation about how to actually deal with this stuff and I want to make sure I'm not giving out bad information. Second question, why does Unsafepointer.dealloc take an int? Shouldn't it know its own size? or is this a concession to situations where you just receive an Unsafepointer<T> from some C API and the runtime has no idea what sizeof(T) is in that case? Third and very minor note, the docs should call out that alloc should get sizeof(T), and the fact that sizeof exists. Oh and why you'd use sizeofValue vs sizeof.
|
# ¿ Jun 28, 2014 15:03 |
|
ljw1004 posted:I'm trying to find in the iBook an explanation for the type system of named tuples... If you pass the values through a function, it works: code:
|
# ¿ Jun 28, 2014 17:24 |
|
rjmccall posted:words Thanks! Corrections made and evil function reference removed. I'm glad you mentioned that, I was actually going to do a post about the truly awful things you can do with it but I'm gonna skip it. Anyone have issues trying to use a framework that includes Objective-C and Swift mixed code? In the project where I'm trying to use the framework, I kept getting errors about the Objective-C (project level) headers not being found, via the swift-bridging-header.h file (again set to project). I ended up having to stick a preprocessor macro in there and #if out the includes from the bridging header unless the framework itself is being compiled. I have the bridging header set as project as well, and verified it does not appear in the .framework directory, but somehow it is being referenced anyway. It apparently works just fine from what I can tell - I'm able to use stuff from my framework without issue... it just feels wrong.
|
# ¿ Jun 28, 2014 18:58 |
|
code:
(rdar://17499275) edit: Crash Golf. The shortest line able to crash the compiler: code:
Simulated fucked around with this message at 17:26 on Jun 29, 2014 |
# ¿ Jun 29, 2014 17:11 |
|
I'm starting to see more and more issues with how protocols use the abstract type alias, or at least some of the limits around them. It effectively erases some of the type parameters, making the protocol itself useless as a type specifier for anyone except the library writer implementing the protocol. Given these definitions from the standard library: code:
The problem is I can't use Sequence at all because it has only the abstract associated types: code:
Why doesn't "var s:Sequence = d" give me a "Sequence<ElementType == (String, Int)>", with the abstract types made concrete? For that matter, why can't I do "var s2 = SequenceOf<Any>(d)"? A tuple is certainly a kind of Any. I'm sure I am not the first to make this argument, nor made it as clearly or cleverly as someone else. I also get why abstract type aliases can be a good thing, to avoid having to give a bunch of extra type parameters to Dictionary in this example, or implementing a bunch of nested interfaces ala C#. It just feels like there is something missing here and all those concrete structs are a sign that something went wrong in the type system somewhere.
|
# ¿ Jul 1, 2014 06:00 |
|
eschaton posted:I think that was referring to filing intentional duplicates to try to inflate priority, like "this bug is a duplicate of 12345, here's some text copied and pasted from a web site, I vote for this feature too!" A few of my Swift bugs were closed as dupes (see below). I'd have to login to check but the other ~20 are sitting there, unexamined, with zero information since the day I filed them. It's been nearly a month. This includes swift compiler hard crash and eternal loop bugs with attached repro cases and crash reports. A simple "tested and reproduced" acknowledgement would be at least minor encouragement. For compiler bugs, Apple should have had some interns whip up a code submission system linked to the bug reports that would allow us to upload sample projects, then run them inside a VM snapshot to immediately verify that the code crashes or loops eternally, roll back the snapshot, then move on to the next submission. A farm of a hundred machines could churn their way through the submissions, probably even at night using spare cycles in existing data centers. Any bug that reproduces a crash could then be cross-checked with existing crashes automatically to determine hot fault paths. The ways the system could be improved are endless. * The big problem with duplicates is that since radar is not public, there is an intermediate window in which a bug is not widely known enough to show up on stackoverflow in google searches, but is far more than a one-off, leading to thousands / tens of thousands (or more) wasted effort by we non-Apple folks to create reproducible test cases and fill out bug reports. That experience is highly demotivating. I endure Apple's bug tracker because it's the one small way I can repay rjmccall's kindness and awesome technical postings over the years. There is nothing positive or pleasant about the experience.
|
# ¿ Jul 8, 2014 05:26 |
|
dizzywhip posted:I think I finally hit Xcode's breaking point. I can edit code for a few seconds before it crashes, locks up for minutes/indefinitely, or Source Kit Services errors out over and over. Hopefully the next update brings some significant stability improvements. I was still enjoying it even when it was barely usable though, I'm super excited to start transitioning over to Swift full-time for 1.0. If certain constructs are present in the code, any partially typed out statement, unmatched braces, half-complete type name, etc will trigger a SourceKit crash for me. I just ignore them; I have a log directory of hundreds (maybe thousands now) of crash reports.
|
# ¿ Jul 16, 2014 21:12 |
|
rjmccall - is there a sanctioned way to cast a C struct? e.g. sockaddr which is treated kinda like a union with sockaddr_in, sockaddr_in6, etc. Other than the verbotten function we've previously discussed, I couldn't find a way to convince swift that an UnsafePointer<sockaddr> is really an UnsafePointer<sockaddr_in>. edit: Answered my own question, it's UnsafePointer<sockaddr_in>(pointerToSockaddr) which just casts the pointer types. 2. What's the difference between UnsafePointer's dealloc and destroy? 3. In idiomatic Swift, for a buffer to receive some data like char or Int8, I'm using UnsafePointer.alloc, but I saw an ArrayBuffer class and one can always use an array itself. Is there a simple preferred way to say "make me a UTF8 character buffer X bytes long"? Or is it mostly dealer's choice? Simulated fucked around with this message at 22:13 on Jul 19, 2014 |
# ¿ Jul 19, 2014 21:46 |
|
ljw1004 posted:rjmcall, I really appreciate all your posts in this thread. I haven't yet figured out how to use radar, but I'll do that tonight or tomorrow night and file all the bugs I've posted here so far. Am still completely new to Apple development. On bugreport.apple.com login and create a new bug (using the now modern iOS 6 UI! At least it isn't original Aqua). Select Developer Tools (it's the Xcode 6 icon). Much of the stuff it asks about is completely arbitrary because there is no option for "Xcode" vs "Swift compiler" vs "Playgrounds" vs whatever else. It all just goes in the dev tools bucket. I usually put Swift: in my subject. Down below in the configuration I just put "Xcode 6 Beta X".
|
# ¿ Jul 22, 2014 23:40 |
|
lord funk posted:Can you quick explain this? I'm falling behind in my Swift blog reading / version updates. http://www.weheartswift.com/one-month-swift/ has a bunch of links Obviously https://developer.apple.com/swift/blog/ is a good one to watch http://andelf.github.io always posts interesting stuff but I have to read it through Bing translate because he mostly posts in Chinese. He's got some posts with dumps of the swift standard library and his github page is my secret sauce for poking at the internals. Mike Ash is covering Swift topics now https://www.mikeash.com/pyblog/ And Brent Simmons does some too http://inessential.com David Owens II has some great stuff https://medium.com/@owensd/latest And there's mine
|
# ¿ Jul 22, 2014 23:50 |
|
ljw1004 posted:
I implemented these extensions for similar reasons and the fact that 9/10 times I just want to provide an alternate value, I don't really care if it is nil. code:
code:
Simulated fucked around with this message at 18:36 on Jul 23, 2014 |
# ¿ Jul 23, 2014 18:29 |
|
rdar://17782662 filed to add the ability to export a module's internal members to another specified module. This makes unit tests on internal members much easier and allows two modules by the same developer to cooperate as if they were the same module, but without making that part of the public API. See also: http://www.russbishop.net/swift-testing-privates
|
# ¿ Jul 23, 2014 20:12 |
|
This is the second time I've started writing this horrible abomination... if I don't get some real reflection soon I won't be able to stop myself from unleashing it upon the world. I am going to get the type's members and their type names one way or another. Also the unknowns are suspiciously in the executable region; brute forcing the function call didn't work but I found someone who figured out the function call trampoline and associated structs. When I get back from dinner that's my next horrible, horrible step. I'm going to put functions inside a dictionary and invoke them later if it kills me. code:
|
# ¿ Jul 25, 2014 01:00 |
|
Flobbster posted:Enjoy the huge rent. I thought I could escape it in San Jose (and did for a year!) but it eventually caught up down here too. Now there's no escaping it. Oh yes, it's crazy. I'm going to try to buy if possible. I just can't pay 3000-4000 a month for an apartment and end up with nothing for it. That said, I have no idea how difficult it is to get a mortgage out there and I hear stories of people coming in with all cash offers, so that's scary too. Simulated fucked around with this message at 01:51 on Jul 25, 2014 |
# ¿ Jul 25, 2014 01:46 |
|
edit: I see what is happening here; those things are @auto_closures and the compiler is breaking down the AST (presumably) and doing other fancy strangeness so you can't actually do anything about it. Simulated fucked around with this message at 05:40 on Jul 29, 2014 |
# ¿ Jul 29, 2014 05:34 |
|
quote:operator infix !! { associativity left } Is there any reason this shouldn't work? The compiler complains that no overloads take the supplied arguments which is incorrect. In theory it should be using the first on x !! y, which produces an optional and so the second would be called with that result and z. If you move "alt" inline the compiler complains about converting a StaticString to String.
|
# ¿ Jul 29, 2014 07:01 |
|
Ok, rdar://17842481 filed Edit: autocorrect Simulated fucked around with this message at 18:45 on Jul 29, 2014 |
# ¿ Jul 29, 2014 17:12 |
|
I did a horrible, horrible thingcode:
|
# ¿ Jul 30, 2014 04:21 |
|
To be fair, I did try something like that but forgot I declared them "let" and the compiler just gave me another "cannot convert to @lvalue $T###" sort of message. I filed rdar://17857686 to ask that Swift output something like "Cannot pass 'let' constant reference to parameter expecting mutable 'inout'". I'm sure you already have a ton of bugs related to type conversion error messages since they're all pretty much like that in beta 4. So what I'm saying is I take no responsibility for my own failures and blame it all on you P.S. Is there any way to get the type names/descriptions that the REPL will spit out? (i.e. find out that i's type is Swift.Int) pre:Welcome to Swift! Type :help for assistance. 1> let i = 5 i: Int = 5 2> let mirror = reflect(i) mirror: _LeafMirror<Int> = { _value = 5 summaryFunction = quickLookFunction = } 3> mirror.valueType $R0: Any.Type = Swift.Int
|
# ¿ Jul 30, 2014 18:17 |
|
Kallikrates posted:The example is derived..., the object implementing the protocol is not a plain NSObject. On the API consumer side, knowing its class X implements protocol Y is helpful when you want to call functions of class X and protocol Y without having to cast back and forth between "id<Foo>" and "X" when I get back to my computer with Xcode Beta ill try (protocol<NSObject, Foo>) but I don't think its a solution because the NSObject protocol only exists for base NSObject, not subclasses, First you don't use NSObject, you use NSObjectProtocol because in Swift you can't name them the same thing since the type names would be ambiguous. Second, this works just fine assuming Foo is a protocol: code:
If you are talking about identifying the return type as being an instance of class X while also implementing protocol Y, then you can use a generic method: code:
|
# ¿ Aug 4, 2014 05:30 |
|
code:
swiftc posted:{a=5, b=1, c=1, d=1, e=1} Wat edit: this works just fine code:
code:
rdar://17973350 and rdar://17973340 Simulated fucked around with this message at 05:36 on Aug 11, 2014 |
# ¿ Aug 11, 2014 05:22 |
|
rjmccall: I just now realized that your team removed @conversion/__conversion. There is not enough room to describe my hate at this moment.
|
# ¿ Oct 7, 2014 06:23 |
|
Basically create a transparent wrapper that can degrade to the wrapped type without having to refactor a bunch of code with useless glue. (It was @conversion that made me think it might be a legit feature.) It's not really hate, I was just getting frustrated trying to write a new class in Swift and call it from Objective-C, I kept running into issues like defining enums in Swift, etc. I also just ran into a case where I greatly miss the ability to say "yes, yes compiler... I know this isn't technically safe, but trust me, class X totally has private members with definition A,B,C so please let me break the rules". The Alamofire library implements didReceiveChallenge and does its own SSL verification. It does not expose the delegates, nor any way to handle that. I am connecting to a system using a self-generated certificate that I know how to validate, but there is no way for me to do so. This is just an example, it could be any situation. If this were Objective-C, I would just declare my own header for the private delegate class and/or swizzle the method and make it work, without having to maintain my own fork of Alamofire (or worse, not having the source). If this were C#, I would use runtime IL generation (or the newer Expression<T> stufF) to create a dynamic method and patch it in, or possibly use reflection to grab and set private fields. Are both of those things hacks? Certainly. Are they absolutely necessary at times, including to work around bugs in system frameworks? Yup. I know that I can assume @objc objects derived from NSObject are usable with the standard Objective-C runtime calls, I just wish Swift had a native way to do it. It can be a pain with big fat "warning: at your own risk" on it, but it should exist. (think "unsafe{}" blocks in C#, which IIRC the default csproj disables so you have to explicitly take responsibility for it) While I'm complaining, is there not a syntax to combine boolean logic and optional unwrapping in one if statement, or even multiple optional unwraps? code:
code:
|
# ¿ Oct 10, 2014 07:22 |
|
rjmccall posted:Can you express that method check using an optional method somehow? If so, it should be as concise as: No, I don't think so. It throws doesNotRecognizeSelector if object doesn't implement hey. I'll double check tonight though.
|
# ¿ Oct 12, 2014 23:11 |
|
code:
|
# ¿ Oct 14, 2014 05:41 |
|
rjmccall posted:Huh. It should definitely be letting you ask for that method with AnyObject-based dispatch. That's a bug. It turns out that Swift demands the selector exists on some protocol somewhere visible to it, then it will allow it. No need to cast or anything, the selector must simply exist.
|
# ¿ Oct 20, 2014 07:23 |
|
rjmccall posted:Oh. Yeah. That's true in ObjC, too. I thought it only requires the selector to exist anywhere, not specifically in a protocol? Also: my kingdom for a way to get the list of possible values for an enum (and the list of associated types for each one if any).
|
# ¿ Oct 22, 2014 04:55 |
|
rjmccall posted:Yes. Is that not true in Swift? If you've declared it somewhere, and exposed it to ObjC with @objc, that's worth a bug. You know what I just re-tested it and it appears to, but it was not working in my real project. I may have some header madness screwing things up. quote:It's on the bucket list. Er, at least the list of possible values for payload-less enums is. Meaningfully enumerating payloaded enums would probably require static or dynamic metaprogramming; what's your goal? Bridge swift enums to Objective-C so when I create entirely new functionality in Swift (that needs to be consumed by old ObjC classes), I don't have to drop back to ObjC just to define an old-fashioned NS_ENUM. For basic raw enums with no functions that inherit from NSInteger or some other integral type obviously Swift could just emit the appropriate C-style enum even though it doesn't today, but I think it makes more sense to expose them as objects. eg: code:
code:
So that and @protocol circular header references are the two really annoying pain points right now. A class which needs to be included in my bridge header also needs to implement a protocol defined in swift. Oops, no-can-do buster! So I end up with Objective-C files that shadow half my Swift classes just to declare protocols and enumerations. I also ran into this hilariousness: code:
I boiled it down to the simplest case and it appears that calling super.init() instead of super.init(nib,bundle) triggers the failure in initialization. If you call super.init() and don't implement override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) you get a nice crash concerning an unimplemented initializer. OK you say, you're calling the wrong initializer for a view controller... Well smartypants, guess what happens if you inherit from UITableViewController and call super.init(style:UITableViewStyle) like a normal person? It behaves as if you had called super.init(), complete with crashes and missing values.
|
# ¿ Oct 22, 2014 07:45 |
|
rjmccall posted:That is a really interesting idea, and I have no idea what to tell you. Metaprogramming, I guess. You can't directly set the style so there is no possibility of calling some other initializer. That makes it impossible to have a UITableViewContoller-derived subclass in swift with an initializer... unless you're banning grouped table views rdar://18747436 Simulated fucked around with this message at 08:28 on Oct 23, 2014 |
# ¿ Oct 23, 2014 08:13 |
|
code:
Oh wait, in a tuple? gently caress right off. rdar://18792507 Also confirmed rdar://18747436 is still alive and well in 6.1.
|
# ¿ Oct 28, 2014 06:33 |
|
Today's random bug rdar://18807413 AKA "7 is a magic number":code:
Trying to do serialization/deserialization has me very nearly tossing this Swift code out and doing it in Objective-C. There's probably a better way that I just can't see right now, but so far its just a lot of manual ["key" : self.key] crap everywhere, and the inverse on the other side. I was trying to coalesce all the json-swift JSValue.errors to see if any errors are present. It was working great up until I hit a larger class. The funny part is in C# I would just use the JSON serializer and literally be done in five minutes; it would automatically map read/write properties bidirectionally, handle arrays/dictionaries, nested values, etc.
|
# ¿ Oct 29, 2014 07:15 |
|
fleshweasel posted:The reason is simply that it allows for chaining and reduction of nil checks. Not that I disagree - I too have run into situations where extending SomeType? would be useful - but you can already chain optional method invocations that way.
|
# ¿ Nov 10, 2014 18:58 |
|
Flobbster posted:I'm always happy to wait for a well-designed general feature than a specific hack I'm really looking forward to what Swift brings to the table w.r.t. generics overall. From what I've already seen in the standard library and what you've talked about wanting to do, I'm hoping that we're going to start getting a lot closer to the power of C++ templates than a lot of other modern languages since then (at least as close as you can get without doing the same substitution-only approach used there). This is equivalent to the "new" constraint in C# and I second the motion. Also big news: very shortly we will be shipping our first Swift code. Other than a few pain points the overall experience makes writing Objective-C seem like COBOL already.
|
# ¿ Nov 12, 2014 06:40 |
|
OK this UIViewController initializer stuff is starting to really drive me crazy. I can't ever create UIViewController subclasses with required properties because it forces me to override initWithCoder and I can't/don't have any useful values to provide in that scenario. That means making constants (let) into optional var properties, which means useless let propName = self.propName! in all my methods. Or just creating a broken init(coder:), heh. That said, I'm starting to default to writing all new code in Swift and I like it. We should be shipping our first Swift code into production shortly.
|
# ¿ Nov 13, 2014 22:19 |
|
I am running into a real pain... when thinking about background downloading, it should be obvious that the entire object graph can be gone when the app resumes and the download task is ready. That means I need to figure out what root object I need and walk the chain of selectors to find the appropriate model to notify so it can update itself. Trying to do this in Swift is really annoying due to lack of any way to invoke methods from a string, even when everything is @objc (aka performSelector isn't imported). Obviously I can work around it by creating utility functions in Objective-C but that just smells wrong. edit: I'm pretty sure getting the IMP and casting through UnsafeMutablePointer/CFunctionPointer can't possibly work. edit2: Well it doesn't work but I can't figure out what I'm doing wrong, because IMP is just a C function pointer and the first two parameters are pointers (id,SEL). Doing the exact same thing with a plain Swift function works fine, I can brutally cast it and make it work as a C function pointer. Doing that with an IMP out of methodForSelector: always barfs. Simulated fucked around with this message at 01:34 on Nov 19, 2014 |
# ¿ Nov 19, 2014 00:33 |
|
I guess arrays of closures are not objects?code:
pre:Type '[OperationBlock]' does not conform to protocol 'AnyObject' pre:Cannot invoke 'synchronized' with an argument list of type '(@lvalue [OperationBlock], () -> () -> $T3)' Simulated fucked around with this message at 00:23 on Dec 20, 2014 |
# ¿ Dec 20, 2014 00:19 |
|
rjmccall posted:Closures aren't objects, and so arrays of closures aren't arrays of objects. Arguably we could make this work, since we do allow our native closure type to be implicitly converted to block type, but we don't currently. Yeah I realized it was a fool's errand, I was just curious why it wouldn't promote them to blocks
|
# ¿ Dec 23, 2014 04:41 |
|
Let's assume I am trying to create a wrapper for a protocol with associated types. code:
|
# ¿ Jan 4, 2015 07:51 |
|
|
# ¿ May 14, 2024 09:37 |
|
rjmccall posted:I don't know, that seems like it should work. Did you try defining typealias EdibleFood = F explicitly? That shouldn't be necessary, but I know that our logic for inferring those associated types has some bugs in it, basically because it's trying too hard to do everything at once. Doesn't appear to work. Created rdar://19371678
|
# ¿ Jan 5, 2015 07:12 |