MosheBerman / KosherCocoa

My Objective-C port of KosherJava. KosherCocoa enables you to perform sunrise-based and sunset-based calculations for Jewish prayer and calendar.
GNU Lesser General Public License v2.1
7 stars 3 forks source link

Issue with array indices when querying Sefira english strings #119

Closed jesiegel1 closed 7 years ago

jesiegel1 commented 8 years ago

https://github.com/MosheBerman/KosherCocoa/blob/master/KosherCocoa/Library/Core/Calendar/Sefira/KCSefiraFormatter.m#L531

The english and hebrew arrays for Sefira strings are of different dimensions, causing the index to be incorrect when querying the english strings and therefore - (NSString *)countStringFromInteger:(NSInteger)integer returns an incorrect value (or just nil).

MosheBerman commented 8 years ago

If the format language is set to English, KosherCocoa adjusts the custom index before doing the lookup. See: https://github.com/MosheBerman/KosherCocoa/blob/master/KosherCocoa/Library/Core/Calendar/Sefira/KCSefiraFormatter.m#L332-L340

_omerCountStringMap is an internal method, so you shouldn't be calling it directly. Instead, use countStringFromInteger: or countStringFromInteger:withPrayers:.

Have you tested this?

jesiegel1 commented 8 years ago

Yea - I wasn't calling it directly, I was calling countStringFromInteger:withPrayers:, but for some reason it wasn't working with English. Once I changed @[[_englishStrings]] to @[_englishStrings], it worked.

jesiegel1 commented 8 years ago

As an aside btw, for some reason adding KosherCocoa to my podfile was installing the incomplete version. I had to specify your latest commit in order to install the library. (Also maybe I can work on it, but we should add an option to countStringFromInteger: for setting attributes - I used a custom font and needed to go in and change the source code to do it.

MosheBerman commented 8 years ago

The way I handle that is by querying the string to get substring ranges after the fact, so the API remains agnostic to the use case. The header words are all pretty unique so you can usually do something like:

  1. Put the headers in an array
  2. For each get the substring range
  3. Apply attributes to that range

This process could be abstracted a little better, perhaps, but that's how I do it. If you file a new issue, we could track it.

MosheBerman commented 7 years ago

@jesiegel1 I just pushed 3.5.1 which should fix this.