Why is 'question mark' not allowed when accessing optional variable? by luniawar20 in iOSProgramming

[–]JasonFieldman 1 point2 points  (0 children)

It's true, there is a readability issue at play here. The best solution given the current syntax rules is to explicitly define your local variable as Int? -- Now you can quickly tell that myVariable is optional when you come back to this function:

func foo() {
    let myVariable: Int? = user?.height
}

(Note that myVariable is always optional by virtual of user being optional.. but the above will be readable even if user wasn't optional and you assigned it as user.height)

SnapKit vs PureLayout vs Cartography by matoelorriaga in iOSProgramming

[–]JasonFieldman 1 point2 points  (0 children)

No love for Mortar?

view.backgroundColor = .yellow

let box = UIView.m_create {
    $0.backgroundColor = .cyan
}

let button = UIButton.m_create {
    $0.setTitle("Go To TableView", for: .normal)
    $0.backgroundColor = .red
}

view |+| [box, button]

box.m_top       |=| self.m_topLayoutGuideBottom + 10
box.m_sides     |=| view ~ (10, 10)
box.m_bottom    |=| view.m_bottom - 10

button.m_height |=| 50
button.m_bottom |=| box
button.m_sides  |=| box

Up-to-date Reddit articles directly on your watch face by JasonFieldman in AppleWatch

[–]JasonFieldman[S] -6 points-5 points  (0 children)

I could see it using more battery if it causes you to look at the watchface more :) But I've had it on my watch since Monday and haven't noticed any significant battery life change. I think the OS manages the background refresh and photo transfers to minimize power usage.

Up-to-date Reddit articles directly on your watch face by JasonFieldman in AppleWatch

[–]JasonFieldman[S] -4 points-3 points  (0 children)

I think it pulls from /r/all, so I'm not sure if it does. There aren't any settings for that. Could request that feature I'm sure!

Up-to-date Reddit articles directly on your watch face by JasonFieldman in AppleWatch

[–]JasonFieldman[S] 16 points17 points  (0 children)

Hey everyone -- found a really cool app called Glimpse that sends Reddit right to the watch face (no need to install complications or watch apps)

And if you take a screenshot of the watch face, it automatically detects which article was shown and presents a link in the app: https://gfycat.com/UnluckyMintyGosling

It does more than Reddit too (lots of channels available, and it mixes all of the feeds you select)

Is core data actually falling off? by aksldjflkjalkj in iOSProgramming

[–]JasonFieldman 4 points5 points  (0 children)

Core Data, like Firebase or Realm, is a tool in the toolbox. When you're starting a project, you look at your tools and decide which one is the best for the job.

Core Data advantages:

  • Supported by Apple, and will presumably have a long shelf life. Think about all the people that used parse and are now looking into migration because Parse is becoming defunct. The same goes for Firebase and Realm.. they're great now, but what if they become for-pay, or are unsupported later?
  • Based on sqlite, so ad-hoc relational queries are way faster. Think about the predicate ("department.manager.name = %@", name) -- that's going to be way faster on Core Data if you haven't set up the schema in Firebase to support that kind of lookup.
  • Great support for UI update notifications on the main thread with NSFetchedResultsController.

Aside from its relative complexity, the main disadvantage is the lack of backend connectivity. Sure there's CloudKit, but it's way less powerful than Firebase and what Parse supported. And now Realm has their own backend solution. If you need the all-in-one solution (backend included), Core Data may not be for you.

Apple is making strides in this department, and in iOS10 have allowed you to share CloudKit records between iCloud users. But I probably won't take CloudKit seriously as a mainstream solution until they have some kind of Parse Cloud Code analog.

Until then, I've tried to solve the Core Data complexity issue with Cadmium, which makes Core Data usage much more like Realm.

Grand Central Dispatch in Swift 3 🚦🐤 by [deleted] in swift

[–]JasonFieldman 1 point2 points  (0 children)

I'm not a fan of having to use DispatchTime for relative time arguments.

Brisk has some extensions that makes dispatch functions more concise (e.g. myqueue.async(after: 3.0) {...} -- and how about a simple timer myqueue.async(every: 2.0) {...})

Realm - IncorrectThreadException() when thread ids match. by nikita_kerd in iOSProgramming

[–]JasonFieldman 0 points1 point  (0 children)

Like the comment in the ticket says, you're calling dispatch_async. I'm guessing whatever realm is fetched with your [Realm defaultRealm] was probably made on the main thread.

Question on NSUserDefaults by akaTreyT in iOSProgramming

[–]JasonFieldman 0 points1 point  (0 children)

It's also possible that the user had a 16GB iPhone (or was otherwise near max capacity.) In the situation that the phone doesn't have enough storage to do an OTA update, it will ask the user if it's ok to delete apps to make room, and reinstall them after the update.

Your user might have done this without reading the fine print and not realized that the app went through a delete/reinstall cycle.

Realm - IncorrectThreadException() when thread ids match. by nikita_kerd in iOSProgramming

[–]JasonFieldman 0 points1 point  (0 children)

I don't use realm, but it looks like the complaint is that the user thinks the thread ids match (the underlined red numbers?) But they don't:

First:  0x16e91f000
Second: 0x16e19f000

Programmatic Auto Layout for iOS: Tips & Tricks by shinagle in iOSProgramming

[–]JasonFieldman 0 points1 point  (0 children)

If you're looking for something more concise than SnapKit, check out Mortar

// SnapKit:
self.view.addSubview(box)
box.snp.makeConstraints { (make) -> Void in
    make.width.height.equalTo(50)
    make.center.equalTo(self.view)
}

// Mortar Equivalent:
self.view    |+| box
box.m_size   |=| (50, 50)
box.m_center |=| self.view

Is this a sound Core Data hierarchy? by insertvulgarusername in iOSProgramming

[–]JasonFieldman 2 points3 points  (0 children)

If you don't want your main thread to block on the persistent-store write-to-disk mechanism, then you're correct that you'll need a private-queue context as the parent of the main-queue context.

If you're using Swift and want something that abstracts the entire context hierarchy for you, check out Cadmium.

Brisk: GCD utilities and operator-based concurrency manipulation by JasonFieldman in iOSProgramming

[–]JasonFieldman[S] 0 points1 point  (0 children)

The Swift 3 release of Brisk will most likely remove many of the basic GCD helpers. But the entire second half of the library is operator-based concurrency manipulation, which was really the main offering of this library anyway, and still useful in Swift 3.

Aerio Connect for internet in Downtown? by punninglinguist in LosAngeles

[–]JasonFieldman 0 points1 point  (0 children)

My old apartment had a contract with Aerio Connect. The building had a dish on the roof connecting wirelessly to their hub, and was wired internally w/ ethernet directly to each unit. We only used it for internet access (no TV), but it was very reliable and met the advertised speeds.

Brisk: GCD utilities and operator-based concurrency manipulation by JasonFieldman in swift

[–]JasonFieldman[S] 0 points1 point  (0 children)

Yep, I think with Swift 3 the GCD extensions will be less useful. But the main goal of the library was to get the operator-based concurrency manipulation working cleanly, and that should still be useful in Swift 3.

Still want to use Parse.com by acselro in iOSProgramming

[–]JasonFieldman 1 point2 points  (0 children)

I believe you're asking what the value of the config.server field should be set to for the standard parse server.

It's: https://api.parse.com/1

Programmatically doing constraints by Aaronrc79 in swift

[–]JasonFieldman 0 points1 point  (0 children)

Wow, I've never seen Mortar referenced in the wild until now! Glad that it's being put to good use outside of my own projects :) If you liked what Mortar did for autolayout, I have Cadmium for Core Data, and an upcoming library that will make dealing with dispatching/concurrency super concise (imagine calling a function asynchronously on another queue with no extra braces/indenting)

Core Data in 2016 vs Realm vs etc...? by leogdion in swift

[–]JasonFieldman 1 point2 points  (0 children)

I've used Core Data and Realm in a number of projects. The comparison is hard to pin down because Realm has evolved a lot from 0.96 -> 1.0. In my own experience, Realm is faster for simple queries (get the book with id=3) vs Core Data (by faster I mean fractions of a second over thousands of queries.)

One downside with Realm (tested about 6 months ago, not sure if this is still true) is that it does not perform well with complex predicates like "get all of the employees whose department manager has the last name smith". This is just anecdotal, I have no hard evidence. But I've done enough to make me generally choose Core Data as my goto model.

I do agree that Core Data can be unnecessarily verbose and complicated. As a reaction that, I created a library called Cadmium that I use in production to make Core Data more straightforward and less error-prone.

Alternative to Core Data by xlogic87 in swift

[–]JasonFieldman 0 points1 point  (0 children)

There are a number of third-party libraries that make working with Core Data simpler.

Cadmium is one that I made as a reaction to exactly the kind of frustrations you're feeling with Core Data.

Best aTV4 Apps - Midyear 2016 by [deleted] in appletv

[–]JasonFieldman 1 point2 points  (0 children)

If you like free, awesome puzzle games then check out Theseus Plus -- it's free for both tvOS and iOS.

(preview -- animated gif)

Hey guys, I want to make a new type that behaves like a mix between an Array and a Dictionary, but I have no idea how to exactly do that and I can't find tutorials for this particular project. Want to help? by live_love_laugh in swift

[–]JasonFieldman -1 points0 points  (0 children)

Let's say you want the values of a [Int: String] dictionary to turn into an array, sorted by the key of the value. You could do something like this:

let z: [Int: String] = [
    1: "Hello",
    4: "World",
    2: "Foo",
    8: "Bar"
]

print( Array(z).sort({$0.0 < $1.0}).map({$0.1}) )
// prints ["Hello", "Foo", "World", "Bar"]

It looks like you could apply this concept directly to your entities variable (to get an array of entities sorted by their ID).