swift3

How can I change style of some words in my UITextView one by one in Swift?

寵の児 提交于 2019-12-20 04:06:22
问题 I have a UITextView with many different words next to each other. When user enters that screen I want to start highlighting some words, e.g.: the first what he sees is a wall of text: one two three #four five six #seven eight nine ten eleven #twelve thirteen fourteen fifteen sixteen some other words #example test whatever #some thing then, after one second, the word four would change style (color), so he would see: one two three #FOUR five six #seven eight nine ten eleven #twelve thirteen

Realm thread safe object with singleton

谁说胖子不能爱 提交于 2019-12-20 03:44:15
问题 So I have a singleton class that manages the current user that is logged into my application. It looks like this class SessionManager { static let shared = SessionManager() var loggedInUser: User? } The problem is that if I want to get that user object from a background thread, I can't as I get the following exception: 'RLMException', reason: 'Realm accessed from incorrect thread.' After some googling I found Thread Safe Reference's. So I changed my class to be something like this instead:

XCTest Unit Test data response not set in test after viewDidLoad

牧云@^-^@ 提交于 2019-12-20 03:23:35
问题 I'm trying to write Unit Tests and currently I try to test a viewController which received data in viewDidLoad() , the data is set after a alamofire request. The problem is, that in my test function when I check the array which should be filled with 10 elements after the successful request, is 0. I've checked if viewDidLoad() in the test is not executed, but it should be, because when I just add elements to another array, which is outside the request, the specific test works. I guess, it has

Distinction between private and fileprivate top-level classes

巧了我就是萌 提交于 2019-12-20 03:14:32
问题 In Swift 3, what exactly is the difference in access control between private class Foo { } and fileprivate class Bar { } assuming both are top-level classes, that is, they are placed directly into a file rather than nested in some other construct? 回答1: There is no difference in your case. The only time that fileprivate differs from private is inside a class, struct, or protocol. 来源: https://stackoverflow.com/questions/43054774/distinction-between-private-and-fileprivate-top-level-classes

Does the initializer of an `open` class need to be open as well?

妖精的绣舞 提交于 2019-12-20 02:34:50
问题 Swift 3 introduced the new open keyword that I'm using in a framework. Does an open class in this framework require an open initialiser to be used outside of said framework, or does the init function inherit the open declaration on the class? For example: open class OpenClass { var A: String init() { // does this init() function need to be marked open? A = String() } } Side question: do the variables in the open class OpenClass inherit the open nature of their class? 回答1: From SE-0117 Allow

How to convert min to hours in swift3?

时间秒杀一切 提交于 2019-12-20 01:59:46
问题 This is my JSON data { "service_facility_id": 1, "service_id": 4, "facility_name": "Fitting", "charge_per_min": 40, "charge_per_km": 50 }, { "service_facility_id": 10, "service_id": 4, "facility_name": "Health Care", "charge_per_min": 100, "charge_per_km": 0 } Currently i'm using Get method to print specific JSON output in X Code. So i managed to Minute( charge_per_min ) value . But I want to display in a label in HH(Hours) format, so how to convert it minute to hours formate and disply into

Get IPAddress of iPhone or iPad device Using Swift 3 [duplicate]

笑着哭i 提交于 2019-12-20 01:58:07
问题 This question already has answers here : Swift - Get device's WIFI IP Address (11 answers) Closed 2 years ago . How to get the device IP Address without using any third party libraries using Swift 3 programming language. Actually I have used following code in order to get the IP Address. func getIPAddress() -> String? { var address : String? var ifaddr : UnsafeMutablePointer<ifaddrs> = nil if getifaddrs(&ifaddr) == 0 { var ptr = ifaddr while ptr != nil { defer { ptr = ptr.memory.ifa_next }

Using GeoFire queries in Swift does not give useful output

心不动则不痛 提交于 2019-12-20 01:55:26
问题 I'm pretty desperate right now because I'm trying to use GeoFire on my Firebase Database to find nearby users. I'm pretty much stuck for two days now. I searched Google and stackoverflow a lot and tried everything I found there but without any success. Now my last hope is to create this thread myself and hope someone can help me. My database pretty much looks like this: users user_id1 email: xxx@gmail.com username: xxx user_id2 email: yyy@gmail.com username: yyy users_locations user_id1

Convert hex-encoded String to String

烂漫一生 提交于 2019-12-19 22:36:48
问题 I want to convert following hex-encoded String in Swift 3: dcb04a9e103a5cd8b53763051cef09bc66abe029fdebae5e1d417e2ffc2a07a4 to its equivalant String : ܰJ:\ص7cï ¼f«à)ýë®^A~/ü*¤ Following websites do the job very fine: http://codebeautify.org/hex-string-converter http://string-functions.com/hex-string.aspx But I am unable to do the same in Swift 3. Following code doesn't do the job too: func convertHexStringToNormalString(hexString:String)->String!{ if let data = hexString.data(using: .utf8){

Convert hex-encoded String to String

只谈情不闲聊 提交于 2019-12-19 22:36:18
问题 I want to convert following hex-encoded String in Swift 3: dcb04a9e103a5cd8b53763051cef09bc66abe029fdebae5e1d417e2ffc2a07a4 to its equivalant String : ܰJ:\ص7cï ¼f«à)ýë®^A~/ü*¤ Following websites do the job very fine: http://codebeautify.org/hex-string-converter http://string-functions.com/hex-string.aspx But I am unable to do the same in Swift 3. Following code doesn't do the job too: func convertHexStringToNormalString(hexString:String)->String!{ if let data = hexString.data(using: .utf8){