optional

Cannot use optional chaining on non-optional value of type 'Auth'

▼魔方 西西 提交于 2019-12-25 21:07:30
问题 var loggedInUser: User? let storageRef = Storage.storage().reference() let databaseRef = Database.database().reference() // structure definition goes here override func viewDidLoad() { super.viewDidLoad() self.loggedInUser = Auth.auth()?.currentUser//Cannot use optional chaining on non-optional value of type 'Auth' self.databaseRef.child("user_profiles").child(self.loggedInUser!.uid).observeSingleEventOfType(.Value) { (snapshot:DataSnapshot) in //'observeSingleEventOfType(_:withBlock:)' has

在javsscript中动态创建qml组件

霸气de小男生 提交于 2019-12-25 15:43:24
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> Dynamic QML Object Creation from JavaScript QML supports the dynamic creation of objects from within JavaScript. This is useful to delay instantiation of objects until necessary, thereby improving application startup time. It also allows visual objects to be dynamically created and added to the scene in reaction to user input or other events. See the Dynamic Scene example for a demonstration of the concepts discussed on this page. Creating Objects Dynamically There are two ways to create objects dynamically from JavaScript. You can either call Qt

Swift nested non-optional structure gives optional

自古美人都是妖i 提交于 2019-12-25 07:48:33
问题 I have the following code: struct Product { var image: URL! var title: String! var price: Price! var rating: Float! var url: URL! } struct Price { var value: Double! var currency: String! // should be enum } I later initialize a Product with: product = Product( image: URL(string: "...")!, title: "...", price: Price( value: 5.99, currency: "CAD" ), rating: 4.5, url: URL(string: "...")! ) During runtime, product.price is of type Price? I find this weird since it's implicitly unwrapped. I've

Optional vs Bound value assigning var from array

谁说我不能喝 提交于 2019-12-25 03:43:14
问题 I want to check if there is a value in a array and if so assign to a String using a if-left statement: if let scoreValue = scoreValueArray[element!]{ // do something with scoreValue } Error: Bound value in a conditional binding must be of optional type So tried changing the ! to ? but error persists. Any input appreciated. scoreValueArray is an array of strings, where a String value is appended to array if a condition is met, then array is saved to NSUserdefaults. So element is a int which

Match Optional Components in Any Order

佐手、 提交于 2019-12-25 02:29:41
问题 I have a URL that can contain any combination of parameters used in filtering results. The two params are type and sort. If type exists in the URL, it has to be either 'article', 'opinion', 'review', or 'media. If sort exists in the URL, it has to be one of the following: date-desc, date-asc, views-desc, views-asc, comments-desc, comments-asc. Right now, the expression I have only matches URI's with both type and sort. And it doesn't match URL's that contain neither params. I would like the

spring-data-jpa @RestController @Repository Optional strange behavior

非 Y 不嫁゛ 提交于 2019-12-24 20:25:28
问题 My @RestController @GetMapping("/projects/{project_id}") public Project getProjectById(@PathVariable(value = "project_id") UUID projectId) { return projectRepository.findById(projectId).orElseThrow(Util.notFound(projectId)); } My projectRepository is @Repository public interface ProjectRepository extends PagingAndSortingRepository<Project, UUID> { } public class Util { static Supplier<ResourceNotFoundException> notFound(UUID msg) { log.error(msg + " not found"); return () -> new

How to use a type from an optional dependency in a declaration file?

你说的曾经没有我的故事 提交于 2019-12-24 17:27:44
问题 I have a JS library that does something like so: let OptionalLib; function foo() { OptionalLib = require('optionallib'); // Do stuff... return (something from optional lib); } then I add typings in a .d.ts file: declare module 'mylib' { import { Bar } from 'optionallib'; export function foo(): Bar; } the problem with this is that if the optional library is not installed, TS will complain about not being able to import it, even though it's optional. I tried doing this in order to have the

Make NSNumberformatter().numberFromString return an optional

家住魔仙堡 提交于 2019-12-24 14:53:18
问题 I'm pretty new to swift. Just wanted to know how to convert the code below to be an optional. var displayValue: Double { get { return NSNumberFormatter().numberFromString(display.text! as NSString)!.doubleValue } set { display.text = "\(newValue)" userIsInTheMiddleOfTypeingANumber = false } } this is from the stanford calculator lecture series. The lecturer didn't show how to make it optional. My understanding is that when there is a string in displayValue that can't be converted to a Double

Need clarification on “@objc class” in Swift

流过昼夜 提交于 2019-12-24 11:36:40
问题 I understand what the "@objc" attribute does for protocols. What I don't understand is why it is added to classes, such as in the following example: @objc protocol CounterDataSource { optional func incrementForCount(count: Int) -> Int optional var fixedIncrement: Int { get } } @objc class Counter { var count = 0 var dataSource: CounterDataSource? func increment() { if let amount = dataSource?.incrementForCount?(count) { count += amount } else if let amount = dataSource?.fixedIncrement { count

'Cannot convert the expression's type' with optional in closure body

北慕城南 提交于 2019-12-24 10:47:46
问题 I have come across (most definitely) a feature that I don't quite understand. I have a closure, that takes in a Float and has no return value, aka (number: Float) -> Void . In that closure, I perform a call on optional value, not forcing its unwrapping, because I like the behavior since the optional is a delegate (= if it's nil, don't do anything). But when I do that, I get an error: Cannot convert the expression's type '...' to type Float. Interestingly enough, when I simply add println() ,