ios


Passing an IBOutlet variable to another class


I'm trying to take an IBOutlet of type UITextField, and use that variable in a function with let constants from another class... How would I go about dong this?
Example:
Class A
Import UIKit
class ViewController: UIViewController {
#IBOutlet weak var userInputTextField: UITextField!
#IBOutlet weak var labelToBeUpdated: UILabel!
}
Class B
Import Foundation
class Data {
let x = 10
let y = 100
}
I would like to take the userInputTextField in Class A and multiply it by x in Class B, then divide it by y in Class B... (userInput * x) / y
Thanks
Actually you can't multiply IBOutlets like text fields ;-)
Create an instance of class Data
Check if the text value of the text field is convertible to Int and do the math by accessing Data's properties.
let data = Data()
if let userInput = Int(userInputTextField.text) {
let result = (userInput * data.x) / data.y
}

Related Links

Disabling Dynamic Type in Swift
how to make overlay with activity indicator programatically
performseguewithidentifier works with a delay
Type [TeamModel] has no subscript members
Pdf file in webview not scrolling
Ternary Conditional Operator for nil/not nil
Xamarin / IOS / Azure - No 'id' member found on type
iOS 9 core location crash
Better accessibility label for a clickable table view cell
iOS add fixed footer UIView to multiscreen app
how to send data from iOS prototype cell to watch with swift 2.2
What does this Google Maps iOS SDK code in Swift do?
Firebase + Swift: Unable to delete rows in tableView
AVfoundation blur background in Video
How to play music in background in Swift with MPMediaPickerController chosen songs?
Assigning to ID Nullable from Incompatible Types

Categories

HOME
validation
odoo-10
jsp
serial-port
android-activity
bootstrap-selectpicker
swashbuckle
libreoffice
weblogic11g
application-cache
freebsd
struts2-jquery
command-line-arguments
sonata-admin
resolve
ellipse
spring-cloud-consul
syswow64
w2ui
atmelstudio
gitlab-ci-runner
jmeter-plugins
hough-transform
polynomials
abstract-syntax-tree
sumifs
phonegap-desktop-app
paket
flatbuffers
gcp
localdb
stackexchange.exceptional
codeskulptor
haxm
aem-6
gradient-descent
p4-lang
jdom-2
caldroid
uitabbarcontroller
h5py
nexus-5
ulimit
mergesort
httpexception
integer-programming
qmenubar
pci
ewsjavaapi
html-form
wrk
sql-mode
android-gps
complement
fasta
tryton
curly-braces
waf
singlepage
callkit
mysql-notifier
mutation
clientid
python-dragonfly
linq2db
voting
chunk-templates
user-registration
translucency
gem
smarty2
mkpolyline
iife
kue
modern-ui
formhelper
zeroclipboard
validform
nawk
jquery-mobile-popup
execcommand
chomsky-hierarchy
sizzle
dependency-walker
sender
timespan
51degrees
harvest
maven-bundle-plugin
cellid
self-organizing-maps
mdi
junitperf
nntp
sharepoint-timer-job
treetop
excel-web-query
sqlitemanager
sharepoint-feature
case-tools

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App