Can you extract the text from a CLKRelativeDateTextProvider? - swift
I'm building up a set of Complications and have come to the CLKComplicationTemplateUtilitarianLargeFlat which only has one textProvider.
I want to display some text, along with a relative date. So I tried doing this:
let date = CLKRelativeDateTextProvider(date: NSDate(), style: style, units: units)
let template = CLKComplicationTemplateUtilitarianLargeFlat()
template.textProvider = CLKSimpleTextProvider(text: "next: \(date)")
But all I get is:
<CLKRelativeDateTextProvider: 0x79860b80>
Can you extract the raw text from the CLKRelativeDateTextProvider or combine it with a CLKSimpleTextProvider in some way?
Pass in the CLKRelativeDateTextProvider object to the format string, as mentioned in Apple's code:
#interface CLKTextProvider : NSObject <NSCopying>
// By passing one or more CLKTextProviders in the format substitutions, you can add text around the output of a text provider.
+ (CLKTextProvider *)textProviderWithFormat:(NSString *)format, ... NS_FORMAT_FUNCTION(1, 2);
#property (nonatomic) UIColor *tintColor;
#end
Here is an example:
id relativeDate = [CLKRelativeDateTextProvider textProviderWithDate:[NSDate dateWithTimeIntervalSinceNow:12 * 60]
style:CLKRelativeDateStyleNatural
units:NSCalendarUnitMinute];
template.textProvider = [CLKTextProvider textProviderWithFormat:#"next: %#", relativeDate];
The time shown in the date provider will still update as time passes without having to refresh anything.
With the current version of ClockKit you can not pull any String data from a text provider nor combine 2 or more text providers. The only text providers available to you are:
CLKDateTextProvider
CLKRelativeDateTextProvider
CLKSimpleTextProvider
CLKTimeIntervalTextProvider
CLKTimeTextProvider
To answer your question you will not be able to display the word "Next" and then a date in your complication. Due to the way ClockKit is designed and the way your complication data should be designed, however, you shouldn't be needing to display "Next" at all. Your complication should be automatically showing the next item from your data relative to the current time.
Related
cant translate text with value using GETX in flutter
the problem is that the text has value which declares the day before the text so idk how to translate this text that includes value. untilEventDay = '${pDate.difference(DateTime.now()).inDays},days/ until event day' .tr; in translation page : ,days/ until next event day': 'ڕؤژ ماوه/ تاوهكو ئیڤێنتی داهاتوو',
you should separate the value's string from your translation var eventDayCountDownTitle = '${pDate.difference(DateTime.now()).inDays}' + ',' + days/ until event day'.tr; and if you need your day number to be in a specific language, you can use a map or a helper method. map solution would be something like this: Map<String,String> englishToPersianNumber = {'1' : '۱'} and then use it in your string : englishToPersianNumber[pDate.difference(DateTime.now()).inDays.toString()] Important: to have a cleaner code, you can create a helper method to generate your desired string, and call it in your text widget. the code would be more understandable that way. Also, you can add handle any conditions that may later be added to the string generator. like if it's the last day, write something else instead of 0 days remaining. String eventDayCountDownTitle(int remainingDays) { if(remainingDays == 0) return "Less than One day to the event".tr; return '${remainingDays.toString}' + ',' + 'days/ until event day'.tr; } ps. your question's title is wrong, you should change it to what you're explaining in the caption
Eliminate repetition in updating strings selected randomly within a state property
First, I'm very new to Swift, and coding in general. I'm trying to use the correct terminology, so I apologize if it makes no sense. Doing my best! Ok, so there appears to be a lot of information/answers on ways to random select strings (or integers, etc) from an array without repetition. However, in my current application, I am not using an array (I kind of am but not directly related to the question). But rather a #State designation, in which the variable has an initial value (a string with a number and letter) and is later updated when a button is pushed. The string changes to a randomly selected string from my assets folder based on the file name, which will be the same word but with a different number and letter. What is the simplest way to keep from updating to strings that have already appeared? Example of what the code looks like: #State var relevantWord = "bird" Button { let randoNum = Int.random(in: 1...5) let x = ["a", "b", "c", "d"] let randoLet = x.randomElement() relevantWord = "bird" + String(randoNum) + String(randoLet) } So, the relevantWord variable starts as "bird2c" for example, and each time the button is pushed, it will change to "bird3b" then "bird4a" etc. I just want to keep it from repeating and return nothing when the assets are depleted. Thanks!
Is is possible to add the data into echart box that appear when mouse-on in bar chart
whitebox The sun withboard box. May i ask that how to append the data and display after search engine. Thankyou.
The way to insert the additional data into tooltip: Declare formatter formatter: function (params) { //params can get the data needed like series name //params is to get the corresponding data that belong to the pointer // var index_ds = params[0].dataIndex (Can use this code to get the index of dataset which is the index where the data come from) //Declare a variable to display the data let additional = "Additional Data" //If want add a new line just like additional += "xxxxx" } The output will be like this: ============================== Additional Data xxxxx ==============================
Conditional formatting for dates
I'm trying to come up with a simple conditional format formula for highlighting cells that have a date that is greater than three months older than today's date. It seems though that the "Date is before" option only gives a few options, none of them seem to allow what I'm looking for. Is there a custom formula that could accomplish this? Edit: attaching a snip of the column in question:
Formula : =DAYS(now(),B2)>90
Go to the custom formula in the conditional formating rules and use this: =DATEDIF(A1,TODAY(),"D")<90
try: =1*C2>DATE(YEAR(TODAY()), MONTH(TODAY())+3, DAY(TODAY())) also make sure you have valid dates and not plain text dates. you can test this with ISDATE formula
You can use Apps Script and a Custom Menu in order to solve your issue with setting the color in the cell depending on the date. Go to Tools->Script Editor and paste this code: function onOpen() { var ui = SpreadsheetApp.getUi(); ui.createMenu('Custom Menu') .addItem('Check Difference', 'dateDifference') .addToUi(); } function dateDifference(){ var sheet = SpreadsheetApp.getActiveSheet().getActiveRange(); // Get the selected range on the sheet var dates = sheet.getValues(); // Get the values in the selected range var oneDay = 1000*60*60*24; var row = 1; var re = /^(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}$/; // This will help you to check if it's really a date dates.forEach(function(el){ // Iterate over each value if(typeof el[0] == 'object'){ // Check if it's really a date var gmtZone = el[0].toString().split(" ")[4].split(":")[0]; // Take the date's GMT var dateFormatted = Utilities.formatDate(el[0], gmtZone, "dd/MM/yyyy"); // Format the date if(re.test(dateFormatted)){ // Test if it's the right format // This part will calculate the difference between the current date and the future date var futureDateMs = new Date(el[0]); var todayDateMs = (new Date()).getTime(); var differenceInMs = futureDateMs - todayDateMs; var differenceInDays = Math.round(differenceInMs/oneDay); if(differenceInDays >= 91.2501){ // Test if the difference it's greater to 91.2501 days (3 motnhs) sheet.getCell(row, 1).setBackground("#00FF00"); // Set the color to the cell } row++; } } }); Save it by clicking on File->Save. Then you can select a range in a column and click on Custom Menu->Check Difference as you can see in the next image: As you can see, you will get the desired result: Notice It's really important to be careful with what you consider to be a "month", I mean how many days you are going to take into consideration. In my code, I took Google's suggestion of 1 = 30.4167. Docs These are other Docs I read to be able to help you: Utilities.formatDate() Working with Dates and Times. I hope this approach can help you.
Making text into an array - Swift
For fun I'm helping my school out by creating an app which has all class cancellations for student use. From my IT technician I got a quite complex structure containing class name, teacher, and other information looking like this: 3818,"20170217",5,752,64,"Rh",,"fr_2",,,,"iV5",,,"IS10a~IS10b~IS10c~IS10d","Z",,1,"IS10a~IS10b~IS10c~IS10d",C,201702161517,"-" 3819,"20170217",6,752,102,"Rh",,"fr",,,,"iB3","iB3",,"IT10a","Z",,0,"IT10a",,201702161517,"-" 3820,"20170217",8,752,119,"Rh",,"fr",,,,"iC1.2","iC1.2",,"IS6a","Z",,0,"IS6a",,201702161517,"-" 3821,"20170227",2,753,207,"Dd","Kru","sc",,,,"iB8","iB8",,"IS9b","Z",,2097152,"IS9b",,201702270804,"+~-" 3822,"20170227",3,753,8,"Dd",,"phH_1",,,,"iB8",,,"IS12~IT12","Z",,2097153,"IS12~IT12",C,201702270804,"-" 3823,"20170227",4,753,29,"Dd",,"phH_1",,,,"iB8",,,"IS11~IT11","Z",,2097153,"IS11~IT11",C,201702270804,"-" 3824,"20170227",5,753,30,"Dd",,"phH_1",,,,"iB8",,,"IS11~IT11","Z",,2097153,"IS11~IT11",C,201702270804,"-" 3825,"20170227",6,753,7,"Dd",,"phH_1",,,,"iB8",,,"IS12~IT12","Z",,2097153,"IS12~IT12",C,201702270804,"-" 3826,"20170227",7,753,327,"Dd",,"COV",,,,"AC1",,,,"Z",,2097153,,,201702270803, 3827,"20170227",8,753,46,"Dd",,"ph_1",,,,"iB8",,,"IS10a~IS10b~IS10c~IS10d~IT10a~IT10b","Z",,2097153,"IS10a~IS10b~IS10c~IS10d~IT10a~IT10b",C,201702270804,"-" From this data I need to get various pieces, such as "20170217" and put them into an array for later use. How would I best do this? For anyone who cares, I added the full snippet below! https://jsfiddle.net/pztwfsq1/
Since there is one dataset per line you can iterate through all lines. Split each line at , and you'll have an array of the information. Similar to this (to give you an idea): let row = "1,Peter,5,92,,Brooklyn" let data = row.components(separatedBy: ",") let name = data[1] // Peter let location = data[5] // Brooklyn