This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func getPetalCenteres() -> [CGPoint] { | |
| let h = radius | |
| let center = CGPoint(x: h/2, y: h/2) | |
| var points: [CGPoint] = [] | |
| let d = petalCount - Double(Int(petalCount)) > 0 ? 1 : 0 | |
| for i in 0..<Int(petalCount) + d { | |
| let angle = (Double(i) + Double(self.scale)) * (360/Double(petalCount)) | |
| let angleInRad = angle*Double.pi/180 | |
| let point = CGPoint(x: center.x + CGFloat(cos(angleInRad) * h), y: center.y + CGFloat(sin(angleInRad)*h)) | |
| points.append(point) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var animatableData: Double { | |
| get {return petalCount} | |
| set {petalCount = newValue} | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func getPetalCenteres() -> [CGPoint] { | |
| let h = radius | |
| let center = CGPoint(x: h/2, y: h/2) | |
| var points: [CGPoint] = [] | |
| for i in 0..<Int(petalCount) { | |
| let angle = (Double(i) + Double(self.scale)) * (360/Double(petalCount)) | |
| let angleInRad = angle*Double.pi/180 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| NotificationCenter.default.publisher(for: .userUpdated).map { notification in | |
| return notification.userInfo?["data"] as! Data | |
| } | |
| .decode(type: User.self, decoder: JSONDecoder()) | |
| .map { $0.name} | |
| .sink { username in | |
| self.usernameLabel.text = username | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| networkService.request(.login(username: username, password: password)) | |
| .flatMap { token in | |
| networkService.request(.playlists(token)) | |
| }.flatMap { playlists in | |
| let playlist = playlists.first | |
| networkService.request(.songs(for: playlist.id)) | |
| }.sink(receiveCompletion: { _ in | |
| UIApplication.shared.isNetworkActivityIndicatorVisible = false | |
| }, receiveValue: { songs in | |
| self.configure(with: songs) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let weatherPublisher = networkSevice.request(.weather(lat: lat, lon: lon)) | |
| let locationImagePublisher = networkSevice.request(.locationImage(lat: lat, lon: lon)) | |
| Publishers.Zip(weatherPublisher, locationImagePublisher).sink { (weather, image) in | |
| self.weatherLabel.text = weather | |
| self.locationImageView.image = image | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let testData = (1...1000000).map { _ in randomString(length: 8) } | |
| func testCombineSwift() { | |
| _ = Publishers.Sequence(sequence: testData) | |
| .flatMap { Publishers.Just($0) } | |
| .map {$0.lowercased()} | |
| .removeDuplicates() | |
| .filter({$0.contains("a")}) | |
| .dropFirst(2) | |
| .sink(receiveValue: { value in | |
| print(value) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let selectedFilter = PassthroughSubject<String, Never>() | |
| let searchText = NotificationCenter.default | |
| .publisher(for: UITextField.textDidChangeNotification, object: searchTextField) | |
| .map( { ($0.object as! UITextField).text } ) | |
| .debounce(for: .milliseconds(500), scheduler: RunLoop.main) | |
| .eraseToAnyPublisher() | |
| let publisher = Publishers.CombineLatest(selectedFilter,searchText, transform: { selectedFilter, searchText in | |
| "\(selectedFilter) \(searchText)" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| _ = Publishers.Sequence(sequence: [1,2,3,4,5]) | |
| .flatMap { Publishers.Just($0) } | |
| .scan(0, +) | |
| .sink(receiveValue: { value in | |
| print(value) | |
| }) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let selectedFilter = PassthroughSubject<String, Never>() | |
| let searchText = PassthroughSubject<String, Never>() | |
| let publisher = Publishers.CombineLatest(selectedFilter,searchText, transform: { selectedFilter, searchText in | |
| "\(selectedFilter) \(searchText)" | |
| }) | |
| _ = publisher.sink { value in | |
| print(value) | |
| } |