Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Doh004
Apr 22, 2007

Mmmmm Donuts...
I'm interested. But I'm curious as to why?

Adbot
ADBOT LOVES YOU

Doh004
Apr 22, 2007

Mmmmm Donuts...
Read some of the book while flying this morning, excited to start trying it out.

Thanks for answering our questions rjmccall!

Doh004
Apr 22, 2007

Mmmmm Donuts...
I think he was trying to be nice by not revealing what her heard because, as rjmccall had mentioned earlier, they try to keep their non released names quiet?

Doh004
Apr 22, 2007

Mmmmm Donuts...
I do iOS development for my job and I figured I should start learning how to use Swift, so I made TicTacToe. If anyone is bored could you please give me some pointers? I definitely found myself doing a lot of stuff incorrectly because I'm so used to Obj-C so I know I didn't do things in the proper "Swift" way (if that even exists?).

https://github.com/BayPhillips/TicTacToe

Thank you!

Doh004
Apr 22, 2007

Mmmmm Donuts...

eschaton posted:

Where are your tests? :colbert:

YOLO

eschaton posted:

You should follow similar naming conventions to Objective-C with Swift, i.e. start properties and method names with a lower-case letter, make the name of a method read as a sentence, etc.

For example, this:

code:
    func PlayersCornerPieces(player: Player) -> [GamePiece]
should be more like this:

code:
    func cornerPiecesForPlayer(player: Player) -> [GamePiece]
similar to how it would be in Objective-C.

The separate model classes should also be in separate files, rather than all in one, for stylistic reasons. More practically they have methods that should really be properties, even computed properties like Player.displayName (for which I did like your use of interpolation, that's what I'd have done too). Also, the type for something like that can be just String, not String!, since you probably don't need to introduce an implicitly unwrapped optional for something like that.

I don't know why I ended up naming a lot of my properties and functions like that. For some reason I started combining C#/Java into it all. But do we really need to stay with the old naming convention? I'm used to it but :saddowns:. Also, howcome you can't right click -> refactor -> rename swift files?

And yeah I need to move those classes into their own files. While I was making it I just kept it in one file so I could see it all while working on it. General code cleanup would be great.

Doh004
Apr 22, 2007

Mmmmm Donuts...

This

Doh004
Apr 22, 2007

Mmmmm Donuts...
Hey, could someone please clarify something in regards to using Swift code in Objective-C for me?

I have a library, "CompatibleAlertController", that I've written in Swift and it works great. I want to also use it in Objective-C, but I want to add a prefix to it because it's "How We Do Things in Objective-C". So I add the following:

code:
@objc(BPCompatibleAlertController)
public class CompatibleAlertController {
// class stuff
This should make it so that when I use the code in Objective-C, I can call it as "BPCompatibleAlertController", right?

If so, why is it that the header file that gets generated for the Swift code to Objective-C ends up looking like this:

code:
SWIFT_CLASS("BPCompatibleAlertController")
@interface CompatibleAlertController
That's the reverse of what I want!

Doh004
Apr 22, 2007

Mmmmm Donuts...
No but I can! I always first assume that I'm doing something wrong and don't want to speak outta my rear end about something. I've never done it before but I'll do it tonight :)

fleshweasel posted:

It doesn't seem stable to try to make the class have different names in the two languages. Living with the prefix in swift is no big deal.

Oh I know, but then I got yelled at because I added the prefix to the library by some nerds.

Doh004
Apr 22, 2007

Mmmmm Donuts...
Are you seeing the errors in the objective-c code that references the swift code in its bridging header file?

Doh004
Apr 22, 2007

Mmmmm Donuts...
Yeah, that's what I'd meant. But yeah, I had a lot of trouble with fake errors that went away when building that were "fixed" when I included it in each file I wanted to use it. :iiam:

Doh004
Apr 22, 2007

Mmmmm Donuts...
Started new job where our new solution is all Swift. Are we doing something wrong where most of the objects aren't debuggable? I can't do po myObject anymore. Just get a slew of lldb errors. Is it some build configuration setting?

Doh004
Apr 22, 2007

Mmmmm Donuts...

Ender.uNF posted:

Check for warnings or problems in your headers. If there's anything amiss it will put lldb into a tailspin.

Hmm there was one about some weird rear end library search header. Trying it now.

pokeyman posted:

I'll get certain files or parts of certain files where any debugger action just spews errors instead. I can't be arsed to track down the problematic parts, but maybe knowing that you're not alone will help.

Ugh this sucks. Do you also have Xcode randomly freak out and have the cursor jump around a file from time to time?

Doh004
Apr 22, 2007

Mmmmm Donuts...
So how the hell do we debug properly? println everywhere?

Doh004
Apr 22, 2007

Mmmmm Donuts...
Thanks for that rjmccall. While I understood about half of what you said, I do know that there's plenty of reasons for stuff not working. Definitely appreciate your perspective on it, just a bit frustrated at how unfinished it is. I know you're saying it should have been called a Beta, and I would have been cool with that label, but it sucks that Apple as a whole isn't calling it that.

This is most definitely not a 1.0.

Doh004
Apr 22, 2007

Mmmmm Donuts...
Hey rjmccall,

How do I println the size of an object in memory? I want to print the size of my NSCache but it yells at me when I try to do a malloc_size(UnsafePointer<NSCache>(self.cache)).

Doh004
Apr 22, 2007

Mmmmm Donuts...

rjmccall posted:

The direct answer is that you can make an Unmanaged reference and then get that as an opaque pointer.

The actual answer is that malloc_size doesn't do what you're hoping. It'll at best print the instance size of an NSCache object, i.e. the amount of storage needed for the ivars of NSCache and its superclasses, not the number of entries in the cache or its current capacity, and certainly not the amount of memory currently being kept alive by a reference from the cache.

Hmm, okay. Would instruments be the true way to get the actual size of those objects than?

Doh004
Apr 22, 2007

Mmmmm Donuts...

rjmccall posted:

Instruments might help. It doesn't look like NSCache has much in the way of API for it; I think you're just supposed to trust that it's doing the right thing.

Yeah, that's what I'm worried about!

But thank you for the help! I've been learning quite a bit as I reinvent the wheel and create my very own super performant (read: non-crashing) image cache.

Doh004
Apr 22, 2007

Mmmmm Donuts...

Kallikrates posted:

Not swift related, but if you have same sized images, or same sized groups of images you should look into Fast Image Cache from Path, its a cool library. We pull very large images out of it with zero latency.

Fully aware of good, proven, image caches out there, definitely. Decision was to run our own so I do as I'm told!

Doh004
Apr 22, 2007

Mmmmm Donuts...
It all depends on the file you're currently editing. The more lines of code it has, the more likely the autocomplete is crashing and burning in the background and unable to actually do anything useful for you (besides causing Xcode to crawl and throw random errors at you).

Doh004
Apr 22, 2007

Mmmmm Donuts...
Anyone else use Circle CI / Travis CI for your builds with tests? Getting a lot of hangups and time outs in our Swift solution. Happens in both xcodebuild and xctool and I'm kind of at a loss.

Doh004
Apr 22, 2007

Mmmmm Donuts...

King of Gulps posted:

I had some SJW <BS> in mine :(


This was pretty funny :respek:

Doh004
Apr 22, 2007

Mmmmm Donuts...
Getting tons of segmentation fault: 11 errors with any action besides Run in Xcode 6.3.1 in our Swift solution.

Anyone else running into this? Googling brings up other issues as well.

Doh004
Apr 22, 2007

Mmmmm Donuts...
*edit* Nevermind, I'm dumb and can't read.

Doh004
Apr 22, 2007

Mmmmm Donuts...
Hey rjmccall,

We're getting segmentation faults during compilation on a select few view controllers. All of them inherit from a base subclassed UITableViewController. This crashes in any configuration where "Swift Compiler Code Generation - Optimization level is set to anything above [None].

We no longer get the segmentation faults after having removed any of the optimization levels. Have you seen this before?

Doh004 fucked around with this message at 23:08 on May 5, 2015

Doh004
Apr 22, 2007

Mmmmm Donuts...
How're folks handling functions in Enums?

Basically, I'm trying to grasp how "big" I allow some of my enums to get.

For example, I have an activity tracker:

code:
public enum Activities : String
{
    // Login/Out
    case Login = "Login"
    case Logout = "Logout"
 }
To which I'd normally pass into a singleton:

code:
ActivityTracker.trackActivity(Activities.Login, properties: ["Hello" : "World"])
I was thinking I could actually prevent access to this all by adding a function in the Activities enum to do just that
code:
public enum Activities: String
{
    public func trackWithProperties(properties: [String: AnyObject]?) -> Void
    {
        ActivityTracker.trackActivity(self, properties: properties)
    }
}
// Then I could do
Activities.Login.trackWithProperties(["Hello" : "World"])

Does this just come down to personal preference?

Doh004
Apr 22, 2007

Mmmmm Donuts...
Perhaps that wasn't the best example ever. I guess I'm more curious to people's thoughts as to when enums should own responsibility of more than just their values.

Doh004
Apr 22, 2007

Mmmmm Donuts...

pokeyman posted:

I'm struggling to come up with a convincing reason for the enum to have anything unrelated to its value. You can certainly have methods, computed properties, and so on, but I reckon they shouldn't involve much beyond the enum itself.

I could see that. Maybe for example I could do:

code:
public enum Activities: String
{
    case Login = "Logged in"
    case Logout = "Logged out"
    case ForgotPassword = "Forgot password"
    
    case OrderCompleted = "Completed an order"
    
    public func isAuthenticationActivity() -> Bool
    {
        return self == .Login || self == .Logout || self == .ForgotPassword
    }
}
I guess that keeps all of that logic within the Activities.

Doh004
Apr 22, 2007

Mmmmm Donuts...
Wish I could be there!

Doh004
Apr 22, 2007

Mmmmm Donuts...
Very cool news, congratulations rjmccall!

Doh004
Apr 22, 2007

Mmmmm Donuts...

Great job rjmccall! Super excited to get our stuff upgraded to 2.0 :D

Doh004
Apr 22, 2007

Mmmmm Donuts...
The more Swift we do, the less and less I'm willing to allow force unwraps to make it through code reviews. Is that completely misguided or is having lots of if lets what we do with Swift?

Doh004
Apr 22, 2007

Mmmmm Donuts...
Playing with Swift 2 and I need to upgrade some code. Why can't I add @availability to stored properties?

code:
@available(iOS 8, *)
private var alertController: UIAlertController!

quote:

Stored properties cannot be marked potentially unavailable with 'introduced='

Thanks!

Doh004
Apr 22, 2007

Mmmmm Donuts...

rjmccall posted:

Not sure, but it probably has something to do with the storage actually needing to exist and be initialized independent of the runtime OS version. I mean, it's not that these are unsolvable problems, but it's something that hasn't been done.

Okay! Just wanted to ask as it is something that I'd really like to be able to do. I have a wrapper that is a compatible UIAlertController for iOS 7. I can't state that the entire class is only available to iOS 8 (therefore defeating the purpose) so I'm kinda unsure of how to proceed with Swift 2. Looks like I might need to refactor it out to a separate subclass?

It's just confusing, because XCode offers this solution for the UIAlertControllerStyle:


It looks like you should be able to do it.

Doh004 fucked around with this message at 15:10 on Jul 8, 2015

Doh004
Apr 22, 2007

Mmmmm Donuts...

rjmccall posted:

If we're offering an illegal fix-it, that's always a bug.

Filed a bug on radar 21726433 :)

Doh004
Apr 22, 2007

Mmmmm Donuts...
Swift is fantastic. The only thing (obviously generalizing here) holding it back is XCode, compilation times, and debugging randomly not working. It's just drat tiring.

Doh004
Apr 22, 2007

Mmmmm Donuts...
He was the same way before WWDC and Swift 2.0 soooo.... :iiam:

Doh004
Apr 22, 2007

Mmmmm Donuts...
Am I just mistaken, but do I need to add my UIViewControllers (and subsequent dependencies) to my test targets in order to unit test them? Particularly in the instance where I would like to instantiate my viewController from a Storyboard.

This is for 1.2 of course. 2.0 can't come soon enough :)

Doh004
Apr 22, 2007

Mmmmm Donuts...
I don't see iOS 7 simulators in Xcode 7 Beta 5 to download. Will they be downloadable in the near future so we can still test for iOS 7?

Meat Street posted:

That's one way, or you can make the methods you want to test (and the classes they're declared in) public. Either way the issue you're running into is that your classes aren't exposed outside the app module, so your test target can't see them.

Sorry I forgot to respond to this. My classes are public; however, when trying to load the storyboard, it assumes it's in the UnitTest module.

Doh004 fucked around with this message at 14:58 on Aug 11, 2015

Doh004
Apr 22, 2007

Mmmmm Donuts...

Ender.uNF posted:

LLDB gets very confused with certain Swift constructs. I haven't been able to find a pattern yet. Seemingly simple classes will cause the debugger to say it can't po self or some local variable. Closures seem to make it worse. In every case the variables pane shows everything just fine.

Like the random nonsense errors you get when the contents of a closure are invalid you just work around it.

I've given up trying to make sense of it. If I really need to debug something really badly, a quick clean, clean build folders and wiping out derived data fixes my problems (sometimes). If that doesn't work, well I just give up for the day and go home.

Adbot
ADBOT LOVES YOU

Doh004
Apr 22, 2007

Mmmmm Donuts...
Anyone have any tips on how to cut down on compilation times? Or rather, how to find out why some files take forever to compile? I ran my build in XCTool and almost every one of our swift files take > 1000ms to compile, with the worst one coming in at > 6000ms.

Google has suggested a tool to merge all swift code into one big file (because multiple files decreases compilation time), cutting down on nested type inference and last but not least: writing code in Objective-C.

  • Locked thread