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

Extend navigation bar under status bar in interface building
UIBezierPath: byRoundingCorners: doesn't work
How To Change The Title Color of an MFMailComposeViewController?
Preventing UIImagePicker memory problems
CoreData. Manage multiple coordinators, in multi thread, multi context
AVPlayer(ViewController): can not play HLS HD video
Duplicate symbols for architecture when using global constants [duplicate]
iOS: UIWebView display link from website [duplicate]
In App Purchases returns error
NSAttributedString with image doesn't work in UITextField?
How to generate iPhone simulator build or .zip file for submit in Facebook for review in iOS
Xcode lost connection with simulator iOS 9
UIView not moving when I change it's x origin in swift
Disabling iCloud backup, tmp directory and replacement of files in path
Type cast class conforming to sub-protocol to parent-protocol in Swift
When searchController is active, status bar style changes

Categories

HOME
asp.net-mvc
asp.net-identity
apt-get
bootstrap-selectpicker
jqgrid
build.gradle
asp.net-mvc-3
stm
coreos
rebus
smartsheet-c#-sdk-v2
javers
drupal-commerce
formio
procedure
contains
centroid
hough-transform
easendmail
slf4j
scalability
phonegap-desktop-app
google-geocoder
buffer-overflow
react-redux-form
kube-dns
pvlib
gridstack
draggable
mask
packaging
drupal-webform
sagepay
atlassian-bitbucketserver
gradle-tooling-api
php-5.5
textangular
simplesamlphp
psycopg2
unityscript
view-source
webloadui
catalina
getelementbyid
plotrix
tealeaf
file-management
xmllint
vlc-android
pager
intrinsics
vimeo-ios
administrator
multiple-files
dual-table
materialdrawer
linq2db
python-2.3
pyenchant
cbc-mode
structured-programming
android-print-framework
scribe
tab-delimited
monk
dotliquid
showcaseview
ducttape
appstore-sandbox
transport-stream
sysadmin
libnids
xcode4.2
git-gui
datadesign
nextpeer
time-limiting
oledbcommand
j#
exact-synergy-enterprise
springboard
unitils

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